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
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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.