What is Python?
Python is a high-level programming language. It is simple to read and understand, making it easy to develop applications rapidly. If you are new to programming, Python is a great language to start. Python's shallow learning curve enables many programmers new to Python to start new projects with the least amount of learning time.
What is a Python interpreter?
Like SQL, Python code is similar to the English language. That makes it easy for us to understand, but not for our computer platforms. Therefore, the easy-to-read Python code we write should be translated into an intermediate language that machines can understand. That is called interpretation. We need a Python interpreter, commonly known as a compiler, to do that.
Python is platform independent
Python is cross-platform, which makes creating applications with Python much more productive. Python can be used to develop various applications, such as Web Applications, games, Machine Learning, Artificial Intelligence, Data Science, Desktop apps, and Web Scraping applications.
History of Python
Python was created in the 1980s by Guido van Rossum. Python's design philosophy emphasizes code readability and simplicity. Python consists of best practices from several other languages, such as ABC, Modula-3, C, and C++.
Why learn Python?
Python is a platform-independent scripting language that is easy to read and understand. Its syntax is similar to English and has less syntax and complexity compared to other high-level languages.
Python is a good entry point for people who are new to programming.
Advantages of Python
- Python is a Beginner's Language, English-like, and has a simple syntax.
- Python supports both functional and object-oriented programming.
- Python is an interpreted language. Python code is interpreted and executed at runtime by the interpreter. It also can be compiled to byte code to build large-scale applications.
- It can be integrated with other programming languages with the least effort.
- It supports lifecycle methods such as automatic garbage collection.
- Python supports GUI applications that can be ported into different platforms.
- Raspberry-pi and Arduino support Python as their programming language
Installing the Python interpreter
Before we write our first line of Python code, we have to have the Python compiler installed on our working platform.
To install the compiler, visit https://www.python.org/downloads and download the recommended compiler version. See the header section of the page to download the recommended version.
Installation is straightforward, no different than any other app installation. Make sure to set the PATH variable during the installation process. Once the installation is complete, open the python shell.
How to open a Python terminal?
In windows, type IDLE in the search text box and press enter. That will open your Python shell. You are ready to code in Python.
In macOS, follow the below steps.
ls -l /usr/local/bin/python*to see all the Python versions.
- Once you know the version you want to use, run
sudo ln -s -f /usr/local/bin/python3.10 /usr/local/bin/python
to change the default version. In my case, I use Python 3.10
python --versionto see the changes.
idle3.10to start the Python terminal.
This will open your Python shell. You are ready to code in Python.
Writing some basic Python commands
Python shell behaves similarly to the windows command line. It interacts with the user by responding to each command input, meaning one command at a time. Below are some sample commands you can issue to shell to familiarize yourself with Python syntax.
>>> import sys >>> sys.version '3.10.7 (v3.10.7:6cc6b13308, Sep 5 2022, 14:02:52) [Clang 13.0.0 (clang-1300.0.29.30)]' >>> sys.version_info sys.version_info(major=3, minor=10, micro=7, releaselevel='final', serial=0) >>> 5.0*2.0 10.0 >>> (4.0**0.5)**0.5 1.4142135623730951 >>> var1=24.5 >>> var2=17.5 >>> var1 24.5 >>> var2 17.5 >>> var1+var2 42.0
As you may have noticed, the Python shell helps test some commands. But it cannot offer anything useful for us to use in the real-world production environment. Once the Python shell window is closed, all the statements you issued are wiped out.
To develop a reusable application, we must save the Python code on a file and execute it as needed. We will use this approach as our code gets longer and more complex.
The next chapter will learn about How to start with python programming.