Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Basics (Retired) Shopping List Lists

input a no which should check which data type is it

input a no or decimal which should check which data type is it

Sorry, I'm not entirely sure what your question is. Can you please try and rephrase it?

how to write a python program which should check which data type after giving a input

2 Answers

To get a Python object's type you can use the type() function. It will return a type object. If you want to check that it equals a particular type, you can do something like this:

a_string = "A String"
type(a_string).__name__ == 'str'  # returns True in this case

For a list of the types that you could check for, see the Python Documentation's page on Built-in Types

thanks

If that answered your question, you should mark my answer as 'Best Answer', so others know that this question has been solved/answered.