Learn

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.

a_string = "Cool String" an_int = 12 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.

Instructions

1.

Call type() on the integer 5 and print the results.

2.

Define a dictionary my_dict.

3.

Print out the type() of my_dict.

4.

Define a list called my_list.

5.

Print out the type() of my_list.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?