Python TutorialPython Data TypesIntroduction to Python Data TypesPython Data TypesPython provides several built-in data types that are used to represent different kinds of information. Here are some of the commonly used data types in Python:Numeric Typesint: Represents integers (whole numbers) like 5, -10, 100.float: Represents floating-point numbers with decimal values like 3.14, -2.5, 0.75.complex: Represents complex numbers in the form a + bj, where a and b are real numbers and j represents the imaginary unit.# intx = 5y = -10# floatpi = 3.14temperature = -2.5# complexz = 2 + 3jw = -1jText Type:str: Represents strings of characters enclosed in single quotes (') or double quotes ("). Strings can contain letters, digits, symbols, and whitespace.# strname = 'John'message = "Hello, World!"Boolean Typebool: Represents a boolean value that can be either True or False. Boolean values are used in conditional statements and logical operations.# boolis_true = Trueis_false = FalseSequence Typeslist: Represents an ordered and mutable collection of items. Lists are enclosed in square brackets ([]) and can contain elements of different types.tuple: Represents an ordered and immutable collection of items. Tuples are enclosed in parentheses (()) and can contain elements of different types.range: Represents an immutable sequence of numbers. Ranges are commonly used in loops and generate a sequence of numbers based on the specified start, stop, and step values.# listfruits = ['apple', 'banana', 'orange']numbers = [1, 2, 3, 4, 5]# tuplecoordinates = (10, 20)person = ('John', 25)# rangecountdown = range(10) # Generates numbers from 0 to 9Mapping Typedict: Represents an unordered collection of key-value pairs. Dictionaries are enclosed in curly braces ({}) and are used to store and retrieve values based on unique keys.# dictstudent = {'name': 'Alice', 'age': 20}scores = {'math': 90, 'science': 85, 'history': 92}Set Typesset: Represents an unordered collection of unique elements. Sets are enclosed in curly braces ({}) and can be created by passing iterable objects or using the set() constructor.frozenset: Similar to sets, frozensets represent an immutable collection of unique elements.# setunique_numbers = {1, 2, 3, 4, 5}# frozensetimmutable_set = frozenset({1, 2, 3})How to check data typesYou can use the built-in type() function to check the data type of a variable or a value. The type() function returns the type of the specified object.Here's how you can use it:x = 5y = 3.14name = "John"is_true = Truefruits = ['apple', 'banana', 'orange']student = {'name': 'Alice', 'age': 20}print(type(x)) # <class 'int'>print(type(y)) # <class 'float'>print(type(name)) # <class 'str'>print(type(is_true)) # <class 'bool'>print(type(fruits)) # <class 'list'>print(type(student)) # <class 'dict'>In the above example:The type() function is used to determine the data type of each variable. The output shows the respective data types enclosed in <class '...'>.You can also use the isinstance() function to check if an object belongs to a specific data type. It returns True if the object is an instance of the specified type, and False otherwise.As an example:x = 5if isinstance(x, int): print("x is an integer")else: print("x is not an integer")In this case:The isinstance() function checks if x is an instance of the int type and prints the corresponding message.