How to Check Data Type of Variables in Python

In this article, you will learn how to check the data type of variables in Python. Let’s say you have 5 variables. In order to…

The post How to Check Data Type of Variables in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to check the data type of variables in Python.

Let’s say you have 5 variables.

# A variable named 'a' with value 123
a = 123

# A variable named 'b' with value "codesource"
b = "codesource"

# A variable named 'c' with value False
c = False

# A variable named 'd' with value ["red", "green", "blue"]
d = ["red", "green", "blue"]

# A variable named 'e' with value {"north", "south", "east", "west"}
e = {"north", "south", "east", "west"}

In order to check the data type of variables, you can use the type() method.

# A variable named 'a' with value 123
a = 123

# A variable named 'b' with value "codesource"
b = "codesource"

# A variable named 'c' with value False
c = False

# A variable named 'd' with value ["red", "green", "blue"]
d = ["red", "green", "blue"]

# A variable named 'e' with value {"north", "south", "east", "west"}
e = {"north", "south", "east", "west"}

print(type(a))
# => <class 'int'>

print(type(b))
# => <class 'str'>

print(type(c))
# => <class 'bool'>

print(type(d))
# => <class 'list'>

print(type(e))
# => <class 'set'>

Note: The type() method functions by returning the class type of supplied argument.

The post How to Check Data Type of Variables in Python appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-22T12:37:40+00:00) How to Check Data Type of Variables in Python. Retrieved from https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/

MLA
" » How to Check Data Type of Variables in Python." Ariessa Norramli | Sciencx - Monday February 22, 2021, https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/
HARVARD
Ariessa Norramli | Sciencx Monday February 22, 2021 » How to Check Data Type of Variables in Python., viewed ,<https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Check Data Type of Variables in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/
CHICAGO
" » How to Check Data Type of Variables in Python." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/
IEEE
" » How to Check Data Type of Variables in Python." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/. [Accessed: ]
rf:citation
» How to Check Data Type of Variables in Python | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/22/how-to-check-data-type-of-variables-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.