Python Forum
type command does not work appropriately
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
type command does not work appropriately
#1
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?
Reply
#2
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  tmdbsimple content type? How to work with it? pythonnewbie138 1 1,416 Aug-01-2020, 08:18 PM
Last Post: bowlofred
  Type hinting - return type based on parameter micseydel 2 2,425 Jan-14-2020, 01:20 AM
Last Post: micseydel
  Python: command “python -m pip install --upgrade pip” doesn't work apollo 2 13,066 Sep-16-2019, 03:11 PM
Last Post: snippsat
  Type function does not work sunnyarora 2 2,449 Mar-15-2019, 10:50 AM
Last Post: sunnyarora
  speech_to_text command doesn't seem to work snakebyte 10 6,838 Sep-18-2017, 09:15 PM
Last Post: snakebyte

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020