Welcome to your Python journey! Before we dive into the language, let’s set up your environment and write your very first Python program.
Download Python:
Visit the official Python website and download the latest version.
Install Python:
Follow the installation instructions for your operating system:
python3 --version
in your terminal.Verify Installation:
Open a terminal or command prompt and type:
python --version
or
python3 --version
If Python isn't recognized, ensure it's added to your system's PATH variable.
Use a code editor like VS Code, PyCharm, or Python’s built-in IDLE.
Create a new file called hello.py
and write the following:
# This is your first Python program
print("Hello, Python World!")
Command Line:
Open a terminal in the file's directory and type:
python hello.py
or
python3 hello.py
IDE:
Most IDEs have a "Run" button to execute the code.
The print
function is used to display text or output in Python. In this case, it prints "Hello, Python World!" to the console.
Python provides an interactive shell to run code line by line.
python
or python3
in your terminal and press Enter.>>>
Try this:
print("Hello from the Python Shell!")
Objective: Create a Python script that prints your name and calculates a basic mathematical operation.
Create a File:
Name the file intro.py
.
Write the Code:
Add the following lines:
# Display your name
print("Hello, my name is [Your Name].")
# Perform a simple calculation
print("The result of 25 + 30 is:", 25 + 30)
Run the Script:
Execute the file using your preferred method (terminal or IDE).
Experiment:
Modify the script to include: