Getting Started with Python
Python is easier to code and learn compared to many other programming
languages. You can write Python programs using any plain text editor, such as
Notepad or Notepad++. Alternatively, you can use an online Integrated
Development Environment (IDE) or install one on your system. IDEs offer
features like a code editor, debugger, and compiler, making it easier to write
and manage Python code. To start writing Python code and performing various
operations, you need to have Python installed on your system.
Check if Python already exists
Most Linux operating systems come with Python pre-installed. To check if
Python is installed on your device, open the terminal using Ctrl+Alt+T and
run the following command:
For Python 2:
python --version
For Python 3.x:
python3.x --version
If Python is installed, it will display a message showing the Python version
that is available.
To install Python on most Linux systems, you can use the following command:
sudo apt-get install python3.8
To begin the installation, you will be prompted to enter your password. This
step is necessary to grant permission for the installation process to
continue. Once you enter your password, you can proceed with the installation
of Python.
When installing Python, you might be asked if you want to allocate additional disk space. To proceed, you typically type "Y" for yes and then press Enter. This allows the installation process to use the necessary disk space for Python.
During the installation process, Python will fetch and install the required packages and modules automatically. This process occurs automatically after you give permission to assign the disk space.
To verify that Python 3.8 is installed correctly, you can enter the
following command in your terminal:
python3.8 --version
This command will display the version of Python 3.8 that is installed on
your system. If Python 3.8 is installed correctly, you should see the
version number displayed in the terminal.
To run your first Python program, which is a simple "Hello World" program,
follow these steps:
1. Open a text editor and paste the following code:
python 3# Python program to print
# Hello World
print("Hello World")
2. Save the file with a `.py` extension, such as `hello.py`.
3. Open a terminal and navigate to the directory where you saved the
`hello.py` file.
4. Run the program by entering the following command:
python3 hello.py
5. You should see the output `Hello World` printed in the terminal,
indicating that your Python program has run successfully.