Python in Termux – Learn Python Programming

Python is one of the most popular programming languages in the world. It is used for web development, automation, artificial intelligence, cybersecurity, data analysis, scripting, and many other tasks. Python is known for its simple syntax, making it a great choice for beginners who want to learn programming. You can install and use Python on Android devices using the Termux application without root access.

Install Python in Termux

To start learning Python on Android, you first need to install the Python package in Termux. The installation process is simple and only requires a few commands. After installation, you can write, edit, and run Python program from the Termux terminal.

Update Termux packages.

pkg update && pkg upgrade -y

Install Python.

pkg install python -y

Check the installed Python version.

python --version

If the version number appears on the screen, Python has been installed successfully.

Learn Python Programming

Create a new Python file.

nano hello.py

Type the following code inside the file.

print("Hello World")

Save the file by pressing CTRL + O, then press Enter. Exit Nano by pressing CTRL + X.

Run the Python file.

python hello.py

The output will be:

Hello World

Python Variables

Create a Python file.

nano variable.py

Add the following code.

name = "Dev"
age = 25

print(name)
print(age)

Run the file.

python variable.py

Variables are used to store information such as text, numbers, and other values.

Python User Input

Create a new file.

nano input.py

Add the following code.

name = input("Enter your name: ")

print("Hello", name)

Run the file.

python input.py

This allows users to enter information through the keyboard.

Python If Statement

Create a file.

nano if.py

Add the following code.

age = 18

if age >= 18:
print("You are an adult")

Run the file.

python if.py

If statements are used to make decisions in Python programs.

Python Loop Example

Create a file.

nano loop.py

Add the following code.

for i in range(1, 6):
print(i)

Run the file.

python loop.py

Loops help repeat tasks automatically.

Useful Python Commands

Show Python version.

python --version

Start the Python interactive shell.

python

Install Python packages.

pip install package-name

List installed Python packages.

pip list

Upgrade pip.

pip install --upgrade pip

Exit the Python shell.

exit()

Python in Termux Overview

Python is a powerful and beginner-friendly programming language that can be used for many different tasks, from simple scripts to advanced applications. By learning Python in Termux, you can practice programming anytime on your Android device and build a strong foundation for web development, automation, cybersecurity, and other technology fields.

SHARE THIS POST: