Lecture On Python Types.
Lecture On Python Types.
Python equips us with many different ways to store data. A float is a different kind
of number from an int, and we store different data in a list than we do in a dict.
These are known as different types. We can check the type of a Python variable
using the type() function.
print(type(a_string))
# prints "<class 'str'>"
print(type(an_int))
# prints "<class 'int'>"
Above, we defined two variables and checked the type of these two variables. A
variable’s type determines what you can do with it and how you can use it. You
can’t. get () something from an integer, just as you can’t add two dictionaries
together using +. This is because those operations are defined at the type level.
Comments:
So type command is used to know the type of data of variables.
For example, if we have defined the following variables as integer, dictionary or
list we can know the type of our data by using the following code:
a_int = 5
print(type(a_int))
my_dict = {}
print(type(my_dict))
my_list = []
print(type(my_list))