Interpreter ignores type() command

Hi All,

Just a green beginner.

*** Python 3.9.10 (tags/v3.9.10:f2f3f53, Jan 17 2022, 15:14:21) [MSC v.1929 64 bit (AMD64)] on win32. ***
*** Remote Python engine is active ***

import numpy as np
x=np.arange(6)
print(x)
type(x)

When run, the print command executes, but the type function command is silent. I tried with PyScripter and a dozen online interpreters, all ignored the type() command except one, Colab. Wonder if I can get a comment?

thanks
Whiffee

Hi @whiffee. First of all, welcome to Python!

Have you tried print(type(x))? Let me explain you what’s happening.

On the Python REPL (called via python, without running files), and some other interpreters, whenever a function returns something (in this case the type of x), it will commonly print it:

>>>def foo():
...    return "Some stuff"
...
>>>foo()
'Some stuff'

But in other interpreters, or when python runs a file, this won’t happen:

$ cat file_with_foo_function.py
def foo():
    return "Some stuff"

foo()
$ python file_with_foo_function.py
$

In this case, if you only want to show something, use print():

$ cat file_with_foo_function_2.py
def foo():
    return "Some stuff"

print(foo())
$ python file_with_foo_function_2.py
Some stuff
$

This should work for you.