Python is a high-level, interpreted, general-purpose programming language. It is widely used for web development, data science, artificial intelligence, automation, and more.
Key Features of Python:
- Easy to read and write with simple syntax.
- Interpreted language (no compilation needed).
- Object-oriented and supports functional programming.
- Extensive standard library and third-party modules.
- Cross-platform compatibility.
- Dynamic typing and memory management.
Example: Hello World in Python
# Print "Hello, World!" to the console
print("Hello, World!") # Output: Hello, World!
Python Installation & Running Programs
You can install Python from python.org. Run programs using:
python filename.py— Run script in terminal/command promptpython -i filename.py— Run interactively- IDEs: VSCode, PyCharm, Jupyter Notebook
Python Modules and pip
Modules allow code reuse. Use import module_name to include modules.
pip is Python’s package manager to install external libraries:
# Install a library pip install numpy # Import and use it import numpy as np arr = np.array([1, 2, 3]) print(arr) # Output: [1 2 3]
Exercises
Exercise 1: Print your name
# Print your name
print("Nisa") # Output: Nisa
Exercise 2: Add two numbers
# Add two numbers
a = 5 # first number
b = 7 # second number
sum = a + b # calculate sum
print("Sum:", sum) # Output: Sum: 12
