Python - how to check object / variable type?

0 points
Asked by:

How can I check object / variable type in Python?

1 answer
0 points
Answered by:

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
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.

❤️💻 🙂