Variables are containers used to store data. They can be compared to containers in the kitchen that hold sugar, salt, and other ingredients.
Here are some examples of variables:
a = 1
b = True
c = "Name"
d = None
Data Types:
Data type is the kind of value that a variable holds. In Python, we can check the type of any variable using the type()
function.
a = 1 # int
b = "1" # str
Here are some examples of different data types:
Numeric data:
int:
3
,-8
,0
float:
7.349
,-9.0
,0.0000001
complex:
6 + 2j
Text data:
- str:
"Hello World!!!"
,"Python Programming"
Boolean data:
- Boolean data consists of values
True
orFalse
.
Sequenced data:
- list: A list is an ordered collection of data with elements separated by a comma and enclosed within square brackets. Lists are mutable and can be modified after creation.
list1 = [8, 2.3, [-4, 5], ["apple", "banana"]]
- tuple: A tuple is an ordered collection of data with elements separated by a comma and enclosed within parentheses. Tuples are immutable and cannot be modified after creation.
tuple1 = (("parrot", "sparrow"), ("Lion", "Tiger"))
Mapped data:
- dict: A dictionary is an unordered collection of data containing key-value pairs enclosed within curly brackets.
dict1 = {"name": "Sakshi", "age":20, "canVote": True}