Contents

Intro to Python


This is a quick introduction to Python for complete beginners.

For a complete guide on how to download Python for your OS, click here.

We can execute a Python program using:

  • IDLE (Integrated Development and Learning Environment)
  • Any IDE of choice (PyCharm, VSCode, Atom, Jupyter Notebook, etc.)
  • The command line (typing “python” in the command line will invoke the interpreter)

Indentation refers to the spacing in front of the lines of code. Python uses indentation to indicate a block of code to execute. We have to make sure that our Python code is indented properly or else it would not work.

1
2
if x > 2:
    print("x is more than 2")

Comments are important when writing a program. Some uses are:

  1. Documentation(describing and explaining the code)
  2. To improve readibility.
  3. To prevent execution when testing code.

In Python, # is used to write a comment.

1
# This is a single line comment.x

There are two ways to write a multi-line comment:

  • by using multiple #
  • by wrapping the code within triple quotes """ """.
1
2
3
4
5
6
7
8
9
# This is a
# multi-line 
# comment. 

"""
This is also 
a multi-line
comment.
"""

Try printing Hello world in any text editpr or an IDE.

1
print("Hello world!")

Save the code as hello_world.py and run the file. You will get the following output:

1
Hello world!

There you go! You just wrote your first Python program. As you can see, Python is easy to understand and programming is not as dauting as most imagine it to be. You can do it!


References:

  1. Python.org
  2. W3Schools
  3. Programiz