Python Data Types
Python Data Types
In computer programming, data types specify the type of data that can be stored
inside a variable. For example,
num = 24
Here, 24 (an integer) is assigned to the num variable. So the data type of num is of
the int class.
We can use the type() function to know which class a variable or a value belongs
to.
Run Code
Output
We have also used the type() function to know which class a certain variable
belongs to.
Since,
5 is an integer value, type() returns int as the class of num1 i.e <class 'int'>
2.0 is a floating value, type() returns float as the class of num2 i.e <class
'float'>
Here, we have created a list named languages with 3 string values inside it.
Run Code
In the above example, we have used the index values to access items from the
languages list.
Here, product is a tuple with a string value Xbox and integer value 499.99.
# create a tuple
Run Code
name = 'Python'print(name)
Run Code
Output
Python
Python for beginners
beginners' respectively.
Run Code
Output
<class 'set'>
Since sets are unordered collections, indexing has no meaning. Hence, the slicing
operator [] does not work.
Here, keys are unique identifiers that are associated with each value.
print(capital_city)
Run Code
Output
Here, we have accessed values using keys from the capital_city dictionary.