How can we know all possible type of a variable? Consider the following example,
n = int(raw_input())
if n<50:
a = 5
elif n<100:
a = 6.8
else:
a = 'abc'
print type(a)
But, It will give output as either 'int' or 'float' or 'str', depending on value of n...
Can't we have all possible types of a variable? For example the above should give an output something like :
{int,float,str}
class.) What are you trying to learn about your code that you can't learn from reading it?Bt,abv) out? Thanks!a, so you know the type ofa. There is no language-feature static-analysis to determine what values (and hence what types)acould have taken; you have to keep track of that.ain python is not even a variable but just a "tag" to its value. This concept is really well explained in Code Like a Pythonista: Idiomatic Python.