Skip to main content

Python Programing Language

A brief overview of the language used in this course

Note☆ Learning Objectives
  • Execute a simple Python Program.

In this section, we will learn a little bit about the history of Python, different Python versions and implementations, and the impact that Python has had on modern-day programming. Let’s begin!

Why Python?

Programmers of all levels prefer Python for several practical reasons:

  • Easy to Learn: Python has a shorter learning curve, allowing programmers to start coding more quickly.
  • Easy to Teach: Teaching Python requires less effort, enabling educators to focus on core programming concepts rather than complex language-specific rules.
  • Easy to Use: Python often allows for faster development of new software.
  • Easy to Understand: Python code is generally easier to read and comprehend.
  • Easy to Obtain and Deploy: Python is free, open-source, and works across different platforms.

Python 2 vs. Python 3

There are two main versions of Python: Python 2 and Python 3.

  • Python 2: An older version that is no longer actively developed for major changes but still receives updates for bug fixes and security issues. It is not compatible with Python 3, so code written in Python 2 needs to be revised to work with Python 3.

  • Python 3: The current and actively developed version of Python, which introduces its own standards and features. Python 3 is not backward compatible with Python 2, and migrating code from Python 2 can be complex and error-prone.

For new projects, Python 3 is recommended. The course will use Python 3, and while there are differences between Python 3 releases, newer versions are compatible with earlier Python 3 versions.

Using a Terminal to write code

Make sure you’ve installed Python first, before attempting the following steps!

Windows

  • On your Windows PC, type “CMD” in the search bar to open the Command Line Prompt

  • Type the following command and hit the enter button:

python

Mac

  • On your Mac, hold the command key and the space bar simulatenously until the “Spotlight Search” window is open. Type terminal in the search bar to open the Command Line Prompt

  • Type the following command and hit the enter button:

python3
WarningInstalling Python

If python is not installed on your PC, this command will not be recognized. If you are trying this on your personal computer, follow the Geting Started section to install python.

If you are sure to have correctly installed python, try this command instead python3

You can start typing python code directly here!

  • Type the following line of code and hit the enter button:
print('Hello World')
  • You should observe that “Hello World” appears in the prompt under the line of code. This is the response of the computer.

print() is a very useful Python function which can help us output information to the user. Just like mathematical functions such as sin(), cos(), python uses functions which have names followed by round brackets. We will learn more about this in the future.

Adding a little More

  • Consider those lines of code:
name = "Alex"
print("My name is " + name)
  • The line name = "Alex" creates a variable called name and assigns “Alex” as its value. We will come back to variables in the future.

  • The second line print("My name is " + name) prints the combined text “My name is” with the value stored in the variable name (which is “Alex”). The “+” sign here will combine the two texts into one.

  • Congratulations! You have written and executed your first lines of code! Now try to print your name and your age in the command prompt.

  • A Command Prompt or Terminal is a text-based user interface which lets us to send commands and interact with the computer.
  • In contrast, the computer Desktop is a graphical user interface which allows you to use the mouse and keyboard to interact more easily with the computer.
  • If you are using a Mac, computer the equivalent app is called: Terminal

Using a code Editor

Most of the time, a program required multiple lines of code to perform a useful task. Therefore, we will be writting code in a code editor such as Thonny, VS Code or PyCharm and saving the Python source code under the extension .py.

But first! You need to install the tool!