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 - 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 on 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 at a python shell is a quick way to run simple or one-time programs.
>>>2 + 2
4
>>>6 + 8
14
>>>"Hello world"
'Hello world'
However, it is best to write the code in a python file (a file ending in .py) for large programs. 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.
Top comments (0)