Season 02 - Introduction to Python Programming
Variables & Data Types
Last week we have seen an example of variables declaration i.e.; x=2. However, let us see some basic rules:
Declarations that are not allowed
0x = "startingwithzero"x-x = "hyphen"x x = "space"Here we can see that the variable y has been assigned the value 2.
Why there is a difference?
| Name | Type | Examples |
|---|---|---|
| Boolean | bool |
True, False |
| Integer | int |
1900, 2000, 203 |
| Float | float |
10.30, 34.56 |
| Complex | complex |
4j, 6j + 5 |
| Text & String | str |
"AI", "Basics" |
| Lists | list |
[ 1 , 2, 3, 4 ] |
| Tuples | tuple |
( 3, 4, 5 ) |
| Dictionaries | dict |
{'course' : "AI" , 'Subject' : "Python" } |
| Sets | set |
{ 4 , 7, 8 } |
x1 = "3"
print("Data Type of x1 is :", type(x1))
x2 = 5
print("Data Type of x2 is :", type(x2))
x3 = True
print("Data Type of x3 is :", type(x3))
x4 = 4j + 1
print("Data Type of x4 is :", type(x4))
x5 = 4.3
print("Data Type of x5 is :", type(x5))Data Type of x1 is : <class 'str'>
Data Type of x2 is : <class 'int'>
Data Type of x3 is : <class 'bool'>
Data Type of x4 is : <class 'complex'>
Data Type of x5 is : <class 'float'>
x6 = [1,3,4]
print("Data Type of x6 is :", type(x6))
x7 = (1,3,4)
print("Data Type of x7 is :", type(x7))
x8 = {1,3,4}
print("Data Type of x8 is :", type(x8))
x9 = {'course' : "AI" , "Subject": "Python"}
print("Data Type of x9 is :", type(x9))Data Type of x6 is : <class 'list'>
Data Type of x7 is : <class 'tuple'>
Data Type of x8 is : <class 'set'>
Data Type of x9 is : <class 'dict'>