Introduction To Python Programming - part 1
Tags: python, programming, beginners, tutorial
Published: 2023-07-31 14:51:06



Python is a popular, high-level, general-purpose programming language. Guido van Rossum invented it in 1991, and the Python Software Foundation continued to advance it. 
Because of its syntax, which was developed with code readability in mind, programmers may be able to express their ideas in fewer lines of code.
Python is a computer language that facilitates rapid development and more efficient system integration.
Python 2 and Python 3 are the two most popular versions. Both are different.



##Beginning with Python programming:
####Finding an Interpreter:
1. Using an Integrated Development Environment ( IDLE)
Before we start Python programming, we need an interpreter to convert and execute our programs. 

Windows: The Python software downloaded from http://python.org comes with IDLE (Integrated Development Environment), one of many free interpreters that can be used to run Python scripts.

Linux: Python is preinstalled on many Linux distributions, including Fedora and Ubuntu. Type "python" in the terminal emulator to see what version of Python you're using. When it launches, the interpreter should print the version number.

Python 2.7 is typically preinstalled on macOS. Python 3 must be manually installed from http://python.org.


Open the command line and enter Python --version to see if Python is installed on your computer. This will display the Python version that is currently installed on your computer. 
If any other message apart from that shows, then Python is not installed on your device. You’ll have to install Python manually from http://python.org/. 
Follow my other article, where I walk you through the process of installing Python on a Windows computer.
[Python installation guide for Windows 11](https://dev.to/akinnimimanuel/python-installation-guide-for-windows-11-o48)


2. Using a code editor 
Alternatively to an IDLE or an interpreter (command line), Python codes can also be written in a code editor. 
Code editors are applications used for writing, editing, and executing Python code. Examples are Visual studio code, PyCharm, Sublime text, Atom, etc. 
For the remainder of this tutorial, I will use Visual Studio Code as my code editor for Python programming. You can easily download and install Visual Studio Code on their official website.
[Download Visual Studio Code](https://code.visualstudio.com/download)

![Official website of visual studio code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vfhhi9fohkrtvd5m4tk.png)

Fig 1a: Official website of visual studio code

###Writing our first program:
Step 1: After downloading the VSC editor, open the code editor and click on the three dashes at the top left.


![A diagram displaying the VSC editor's user interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dfc6zmj7m1y5u2i9ydze.png)
Fig 1b: A diagram displaying the VSC editor's user interface


Step 2: Click on the file and then the new file to name your first Python file.


![A diagram displaying the VSC editor's user interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8dddh7u1knspf71g2b92.png)
Fig. 1c: A diagram displaying the VSC editor's user interface


Step 3: You can use any naming scheme for your file, but make sure it ends with .Py extension.


![A diagram displaying the VSC editor's user interface](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vg46yvkr2nxv8upac3k4.png)
Fig. 1d: A diagram displaying the VSC editor's user interface

Step 4: Just type in the following code after naming your Python file: The codes shown below will be explained later in this tutorial 

![Python codes written in the Visual Studio code editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q7t5qn3sbsphal4m36vl.png)

Fig. 1e: Python codes written in the Visual Studio code editor

Line 1: print(‘hello, world’) 
Line 2: print(‘Python is awesome and simple’)
Line 3: print(‘My name is Akinnimi Stefan’)
NOTE: I used single quotes here  ' '; you can also use       double" " quotes. But for consistency, you need to choose one and stick to it.
To print something on the console, the print() function is used.


Step 5: Executing or interpreting the code
After typing in the codes, the next step is for you to click on the Run Python File button in the upper-right corner of the editor.

![Executing our first Python program](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mglityoy46u1x8mr9rha.png)

Fig. 1f: Executing our first Python program


Step 6: A Terminal will open (similar to the command line on a Windows or Mac OS laptop), your program will be executed, and the results will be shown as seen below.

![A diagram showing the output of the first Python program](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hs78pzliatmctffdr5je.png)

Fig. 1f: A diagram showing the output of the first Python program

Output:
The output of Line 1 - Hello World.
The output of Line 2 -  Python is awesome and simple.
The output of line 3 - My name is Akinnimi Stefan

Congratulations! 
Your first Python program has been created and run successfully.







##Python Syntax
Syntax means rules that govern the use of a particular programming language. 
The print Program
The print() function prints the specified message to the screen or other standard output device.

![Python codes written in the visual studio code editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icw7d0qsd1zu6ui5bmoq.png)

Fig. 2a: Python codes written in the visual studio code editor

##Python Indentation
Indentation is the term used to describe the spaces at the start of a code line.
Whereas in other programming languages, the indentation in code is for readability only, the indentation in Python is significant.
A block of code is identified in Python through indentation.

![A diagram showing the indentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0gc9k8ooelnjffn2r4ub.png)

Fig. 2b: A diagram showing the indentation (four spaces or two tabs).


![Output of a successfully written Python code with indentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bzjaomiy1mc41jynnvil.png)

Fig. 2c: Output of a successfully written Python code with indentation

NOTE: If you omit the indentation, Python will throw an error as seen in the image below.



![Visual Studio Code showing an error because of the absence of a proper indentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwcgh71ac2q0siobq1dk.png)
Fig. 2d: Visual Studio Code showing an error because of the absence of a proper indentation



![Output of an executed Python program without proper indentation ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0y8xvqew2pc7rbjxgxqg.png)
Fig. 2e: Output of an executed Python program without proper indentation 

As a programmer, you can choose the number of spaces; the most usual use is four, although there must be at least one.