Frequently asked Questions Python Tutorial

There are some questions that come up fairly often, and are things that were never actually explained to me either when I was first starting out. I thought it would be good to cover a few of those here!

The first one is this whole if name == main thing. Here's an example:

if __name__ == '__main__':
    print('such great module!!!!')

Here, I suggest you reference the video for a full example of how this works, but, basically, if name == main asks whether or not the script is the "main" running script, or if that script is just being referenced by another script. Whenever you import other people's code, they usually have these there, so that, when you import them, their code doesn't just automatically run.

Another curiosity people often have is this other bit of code placed at the top of scripts. Something like:


This is what is known as the "shebang" line. It is used for Unix operating systems so the script will execute with Python. If you are on Windows, this is probably totally foreign to you!

Also, while not covered in the video above, I thought I should also add something I forgot to mention at all so far, and that's comments. You've seen my use of the # symbol. That works to create a single line comment like:

# this is a single line comment

You can also do multi-line comments like:

Multiple line comment, can use triple "double quotes" as well to do this.

Finally, you can use triple quotes to do large prints, like:


This is a massive print, where you want to
use multiple lines, maybe make designs, or
something like that. 


I may add more to this page over time, but those should cover it. Those are things that I never saw in any tutorial (besides the comments), but I think they leave people confused.

The next tutorial:

  • Python Introduction
  • Print Function and Strings
  • Math with Python
  • Variables Python Tutorial
  • While Loop Python Tutorial
  • For Loop Python Tutorial
  • If Statement Python Tutorial
  • If Else Python Tutorial
  • If Elif Else Python Tutorial
  • Functions Python Tutorial
  • Function Parameters Python Tutorial
  • Function Parameter Defaults Python Tutorial
  • Global and Local Variables Python Tutorial
  • Installing Modules Python Tutorial
  • How to download and install Python Packages and Modules with Pip
  • Common Errors Python Tutorial
  • Writing to a File Python Tutorial
  • Appending Files Python Tutorial
  • Reading from Files Python Tutorial
  • Classes Python Tutorial
  • Frequently asked Questions Python Tutorial
  • Getting User Input Python Tutorial
  • Statistics Module Python Tutorial
  • Module import Syntax Python Tutorial
  • Making your own Modules Python Tutorial
  • Python Lists vs Tuples
  • List Manipulation Python Tutorial
  • Multi-dimensional lists Python Tutorial
  • Reading CSV files in Python
  • Try and Except Error handling Python Tutorial
  • Multi-Line printing Python Tutorial
  • Python dictionaries
  • Built in functions Python Tutorial
  • OS Module Python Tutorial
  • SYS module Python Tutorial
  • Python urllib tutorial for Accessing the Internet
  • Regular Expressions with re Python Tutorial
  • How to Parse a Website with regex and urllib Python Tutorial
  • Tkinter intro
  • Tkinter buttons
  • Tkinter event handling
  • Tkinter menu bar
  • Tkinter images, text, and conclusion
  • Threading module
  • CX_Freeze Python Tutorial
  • The Subprocess Module Python Tutorial
  • Matplotlib Crash Course Python Tutorial
  • Python ftplib Tutorial
  • Sockets with Python Intro
  • Simple Port Scanner with Sockets
  • Threaded Port Scanner
  • Binding and Listening with Sockets
  • Client Server System with Sockets
  • Python 2to3 for Converting Python 2 scripts to Python 3
  • Python Pickle Module for saving Objects by serialization
  • Eval Module with Python Tutorial
  • Exec with Python Tutorial