Intro to Python
This is a quick introduction to Python for complete beginners.
1 Getting started
1.1 Installation
For a complete guide on how to download Python for your OS, click here.
1.2 Executing Python code
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)
2 Python syntax
2.1 Indentation
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.
|
|
2.2 Comments
Comments are important when writing a program. Some uses are:
- Documentation(describing and explaining the code)
- To improve readibility.
- To prevent execution when testing code.
2.2.1 Single line comments
In Python, #
is used to write a comment.
|
|
2.2.1 Multi-line comments
There are two ways to write a multi-line comment:
- by using multiple
#
- by wrapping the code within triple quotes
""" """
.
|
|
2.3 Your first program
Try printing Hello world in any text editpr or an IDE.
|
|
Save the code as hello_world.py
and run the file. You will get the following output:
|
|
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: