- Data Type represents the type of data present inside a variable.
- In Python, we are not required to specify the type explicitly. Based on the value provided, the type will be assigned automatically. Hence Python is a Dynamically Typed Language.
- Boolean: The type of the built-in values
True
andFalse
. Useful in conditional expressions, and anywhere else you want to represent the truth or falsity of some condition. Mostly interchangeable with the integers 1 and 0. In fact, conditional expressions will accept values of any type, treating special ones like booleanFalse
, integer 0 and the empty string""
as equivalent toFalse
, and all other values as equivalent toTrue
. But for safety’s sake, it is best to only use boolean values in these places. Numeric types:
- int: Integers; equivalent to C longs in Python 2.x, non-limited length in Python 3.x
- long: Long integers of non-limited length; exists only in Python 2.x
- float: Floating-Point numbers, equivalent to C doubles
- complex: Complex Numbers
Sequences:
- str: String; represented as a sequence of 8-bit characters in Python 2.x, but as a sequence of Unicode characters (in the range of U+0000 - U+10FFFF) in Python 3.x
- bytes: a sequence of integers in the range of 0-255; only available in Python 3.x
- byte array: like bytes, but mutable (see below); only available in Python 3.x
- list
- tuple
Sets:
- set: an unordered collection of unique objects; available as a standard type since Python 2.6
- frozen set: like set, but immutable (see below); available as a standard type since Python 2.6
Mappings:
- dict: Python dictionaries, also called hashmaps or associative arrays, which means that an element of the list is associated with a definition,
Note: Python contains several inbuilt functions
1) type() : to check the type of variable.
- a = ('Python', 'Data', 'Type')
- b = "Tipszon"
- c = 33
- x = type(a)
- y = type(b)
- z = type(c)
- print(x)
- print(y)
- print(z)
Output
- <class 'tuple'>
- <class 'str'>
- <class 'int'>
2) id() : to get address of object
- x = ('Python', 'Data', 'Type')
- y = id(x)
- print(y)
Output
- 74768637
3) print() : to print the value
0 Comments
If you have any doubts, Please let me know