Introduction to Python Programming - Getting Started
Introduction
Python is a general-purpose, high-level programming language released in 1991 by Guido van Rossum. A high-level language is closer to human language, while low-level languages are closer to machine language (binary 0s and 1s).
Python is an interpreted language meaning that its code runs without needing compilation. Code written in languages like C/C++ requires and uses a compilation step to generate some artifacts. One such artifact is executable files (ending with .exe in windows and .out in linux).
Python is also a dynamically typed language. A fancy way to say that Python variables can hold different value types anywhere in a program. For example:
# age is an integer
age = 45
# age is now a string
age = "Forty-five"
In statically typed languages like C++, Java, etc., a variable cannot be set into a different type after it has been created (at least without the use of some tricks).
Why would you want to learn Python
Python is a great programming language because:
-
It is popular - and increases the chances of getting Python jobs. Its popularity also makes it easy to get help when faced with problems.
-
It has versatile use - web, data analytics, ML, desktop, security, etc., and
-
It has easy-to-learn, concise, and readable syntax.
-
It is interpreted and
-
Supports programming paradigms (procedural, object-oriented, functional).
-
It is an excellent place to learn programming concepts before moving to other languages.
I said Python is easy?
Let's print "Hello world" in Python:
print("Hello world")
Here's an equivalent ceremony in C/C++:
#include <stdio.h>
int main() {
prinf("Hello world\n");
}
Java too:
class PrintHello {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
Why you wouldn't want to learn/use python
- Python might be very slow for some use cases such as systems programming and production-grade machine/deep learning models. Well, this slowness is generally a problem with interpreted languages. In such cases, languages like C/C++, Rust, and Java are faster.
Installing Python
-
Go here to download Python for your operating system. Then click the download file and follow the prompts to install it.
-
In the installation prompt, check Add Python to PATH so you can assess the program anywhere when using the command line and make it easier for code editors to find python.
-
Optionally, install a code editor like VSCode or an IDE like Pycharm. They make writing python easier.
Tip: VSCode is lighter. Use it primarily when you use a not-so-fast machine.
Testing Your Python Installation
-
At the command line/shell, type
python
and press enter. The Python command displays the Python shell shown in the image below! -
Type
name = "Hello"
and press enter. -
Type
name
and press enter. You will see the content of the name variable printed out on the console. -
Optionally, search for the Python manual and pin it to your taskbar. The documentation is a great way to learn Python.
Running a Python program
You can run a python program directly in an interactive Python shell or REPL. Running Python in a shell is a quick way to run simple or one-time programs.
>>>2 + 2
4
>>>6 + 8
14
>>>"Hello world"
'Hello world'
However, writing the code in a Python file (a file ending in .py) for large programs is best. Execute the Python file at a console by running python whatever_name_it_was.py
. Code editors and IDEs can simplify the running of Python codes.
Conclusion
Python is a great place to start your programming journey as it is relatively easy to learn.