Languages

Python - how to check object / variable type?

0 points
Asked by:
Zachary
286

How can I check object / variable type in Python?

1 answer
0 points
Answered by:
Zachary
286

You can use the type() function.

Practical example:

my_string = 'abc'
my_int = 123
my_bool = True
my_list = [4, 5, 6]
my_dict = {'a': 1, 'b': 2, 'c': 3}

print(type(my_string))  # <class 'str'>
print(type(my_int))     # <class 'int'>
print(type(my_bool))    # <class 'bool'>
print(type(my_list))    # <class 'list'>
print(type(my_dict))    # <class 'dict'>
0 comments Add comment
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join