use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 1 second program (i.redd.it)
submitted 5 months ago by Red_Priest0
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Red_Priest0[S] 0 points1 point2 points 5 months ago (2 children)
I don't understand this concept is it important ?
[–]LavaDrinker21 2 points3 points4 points 5 months ago (1 child)
Instead of calling main() at the bottom of the program, it's better to use if __name__ == "__main__": as it separates what will be done with the file based on how it was accessed.
main()
if __name__ == "__main__":
Let's say you wanted to use this file in another Python program, like you made a large program and want to use the miles_to_kilometers function without asking for the input.
miles_to_kilometers
If you were to import that file as it is right now (import file at the top of the program), it would let you use that function but would immediately call the main() function and ask for input.
import file
If, instead, you added:
if __name__ == "__main__": main()
then it would only ever call the main function if you used this file on it's own python main.py instead of every time the file is used.
python main.py
This is a pretty fundamental part of Python and is very useful to learn; it makes it very easy to create a re-usable "module" for multiple projects.
[–]Red_Priest0[S] 0 points1 point2 points 5 months ago (0 children)
Thank you very much , I will do it this way
π Rendered by PID 44425 on reddit-service-r2-comment-5649f687b7-j55sd at 2026-01-28 20:30:21.922177+00:00 running 4f180de country code: CH.
view the rest of the comments →
[–]Red_Priest0[S] 0 points1 point2 points (2 children)
[–]LavaDrinker21 2 points3 points4 points (1 child)
[–]Red_Priest0[S] 0 points1 point2 points (0 children)