Introduction and Setup.
Python, is one of the most widely used programming languages in the world today. Its syntax is relatively easy to understand and there's a large number of libraries that offer a multitude of functionality. Python is a versatile language and can be used across many areas of software development, from basic scripts, simple to advanced backend (server-sided) web applications, blockchain development, data science and Artificial Intelligence amongst others.
Python was created by Guido van Rossum (a Dutch Developer) way back in the 1990's and fits across many programming paradigms , procedural, functional, object orientated... It is this flexibility and simplicity that bring us to learn python. Python comes in different flavours in terms of what the core the language is written in. The most common Python is CPython, with a core written in the 'C' language, and some core modules written in Python itself. For a roundup of the different flavours of Python see Python Flavours
Everything in Python is an object, variables, functions, classes, everything.
Python is a semi-interpreted language. It's a little bit tricky to explain to a novice, but when Python code is imported from one file to another, i.e. a Python Package it gets
converted into a compiled bytecode file a .pyc
file. However, the interpreter can use both .py
and .pyc
files using the Python Virtual Machine (pvm).
The compiled bytecode .pyc
files are created from the standard .py
files but instead of containing normal Python code they contain a bytecode representation of that code.
Since Python 3.2 .pyc
files are stored in a __pycache__
folder - more often than not this folder can be found in the same location as the related .py
files.
The main python script that runs your program i.e. main.py
or whatever you call it will not be converted to a .pyc
file unless it is imported via some bootstrap.
Don't worry too much about all this at this point. You'll get to know how Python works under the hood as you become more experienced with the language itself. For the time being
it is enough to know that to use Python we need to install the Python Virtual machine, which we just think of as installing Python itself.
Installing Python
Follow the setup instructions to install Python interpreter (version 3.10) from https://www.python.org/downloads/.
There are numerous IDEs (Interactive Development Environments) that can be used to help us develop in Python, one of the best known and widely used being PyCharm, there are free student and community editions available online at https://www.jetbrains.com/pycharm/. If you do not wish to use PyCharm, you may use any other IDE that supports Python.
Once you have decided on, and installed your preferred IDE, make sure it is using a version of Python 3, preferably 3.10 or higher.
As previously stated, when we write code using an IDE in a .py
file and then run it, the IDE will, in the background, invoke the python interpreter to process our code and execute it.
All IDEs that cater for python will automatically generate the .pyc
file containing bytecode. this is the file that will now be taken, line by line, by the interpreter and
converted into machine code that runs on your computer. Unlike a complied language such as C, C++
the conversion to machine code from bytecode happens everytime you run
your Python code.
Setting up our learning project
Open your IDE and create a new Python project (setting-up-our-learning-project"Using PyCharm - from the menu File > New Project > Pure Python
).
NOTE: For an introduction to the Python interpreter and how to use it, refer to Python Docs
We also encourage you to study the Python coding style guidelines here PEP8