Type checking in python!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Type checking in python!!

if a user inputs data in python its a string............. how to distinguish between various data types

26th Jul 2017, 8:31 AM
Bharath Kumar
3 Answers
+ 4
thanks man!!
26th Jul 2017, 9:11 AM
Bharath Kumar
+ 2
you can use var=int(input("enter a number")) to transform the input in an int if you want to be sure that the user will enter a number i think you can use a try/except
26th Jul 2017, 8:47 AM
Matte
Matte - avatar
0
the question is not clear.. do you want to check the datatype of a variable? it can be done by "type(variable name)" if you want to compare types of two variables it can be done as follows "type(variable 1)==type (variable 2)" you can change type of a variable like matte said..
20th Aug 2017, 7:53 PM
Yagnavalk Chaapala
Yagnavalk Chaapala - avatar