Python Forum
type command does not work appropriately - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: type command does not work appropriately (/thread-10653.html)



type command does not work appropriately - atharva - May-30-2018

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?


RE: type command does not work appropriately - buran - May-30-2018

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)



RE: type command does not work appropriately - Larz60+ - May-30-2018

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?