Python Forum

Full Version: type command does not work appropriately
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
when I assign a variable as given below type command works
for example :-
a = 2
type(a)
but when I assign a variable as given below and save it as .py file and run it does not what it should.
a = 2
b = 3.0
c = "string"
type(a)
type(b)
type(c)
please help me understand what is the reason behind this?
In the first case you work in the interactive mode, i.e.
>>>a = 2
>>>type(a)
<type 'int'>
when in py file it still works, but you don't 'see' the result. you need to print it in some form or use it in any way, e.g.
a = 2
b = "some string"
print(type(a))
what_type = type(b)
print(what_type)
from module:
a = 2
b = 3.0
c = 'string'
print(type(a))
print(type(b))
print(type(c))
save in foo.py then run foo

Output:
M:\ λ python foo.py <class 'int'> <class 'float'> <class 'str'>
Do you think something as simple as this wouldn't have been discovered by version 3.6.5?