Weird behavior - OOP print function

In step 1 of Object Oriented python, Data Analysis course, the instruction 1 shows some weird behavior. If I didnt put a print statement for the last line, my output is different from the one that the solution expect. without print, the type function didnt return the keyword “class”. wonder why is that.


But if I add print function to the last line of code it works fine.


how a print function can change the output of the code?

1 Like

The output does not match the expected result. Most probably the checker expects the printed output.

yes, but why did type(d) produced an output of dict instead of <class ‘dict’> ?

I am assuming the interface is an interactive python.

Interesting question! :thinking: I’ve only been using python for a couple months, but I wonder if it has to do with the behavior of what is being used to run the code. In Jupyter Notebook I see the same thing. When I tried something similar with python from the command line, however, both type(d) and (print(type(d)) gave me an output of <class 'dict'>! I don’t really know how that works, but that would be my best guess at why you’re seeing a difference in the output.

1 Like

thank you. I see the same thing. When I run the same code from Jupyter I am getting same output where as from python command line getting <Class ‘dict’>

how does it matter. why should the output differ for same line code.

type does not output to the output stream.
Whereas print sends the output to the output stream.