r/learnpython • u/AutoModerator • 24d ago
Ask Anything Monday - Weekly Thread
Welcome to another /r/learnPython weekly "Ask Anything* Monday" thread
Here you can ask all the questions that you wanted to ask but didn't feel like making a new thread.
* It's primarily intended for simple questions but as long as it's about python it's allowed.
If you have any suggestions or questions about this thread use the message the moderators button in the sidebar.
Rules:
- Don't downvote stuff - instead explain what's wrong with the comment, if it's against the rules "report" it and it will be dealt with.
- Don't post stuff that doesn't have absolutely anything to do with python.
- Don't make fun of someone for not knowing something, insult anyone etc - this will result in an immediate ban.
That's it.
5
Upvotes
View all comments
Show parent comment
2
u/lakseol 24d ago edited 23d ago
You are probably using an IDE, and it's easy to think that
printandreturndo much the same thing. Run this code in your IDE and note what prints:Then put the code into a file, say test.py, and using the command line move into the directory containing that file and do:
and see what prints. Then change the last two lines to:
and repeat the two executions, one in your IDE and the other on the command line. Can you explain the difference?
To explain the difference you have to understand that the IDE is doing something (as a convenience) that python itself doesn't do: it automatically prints any non-None value of a statement.
Update: simplified the example code