ProgrammingBeginner

Python for Beginners: Your First Program

Start your Python journey by writing your first programs and understanding basic syntax.

Python for Beginners: Your First Program
5clear steps

Before you begin

  • Basic computer skills

The walkthrough

Step by step.

01

Step 1 of 5

Installing Python

Visit python.org and download the latest version. During installation, check "Add Python to PATH". Verify installation by opening terminal and typing: python --version

Field note
  • Use Python 3.x (not Python 2)
  • Install a code editor like VS Code or PyCharm
02

Step 2 of 5

Your First Print Statement

Create a new file called hello.py. The print() function displays output to the console.

python
# Your first Python program
print("Hello, World!")
print("Welcome to Python programming")

# Print multiple items
name = "Alice"
print("Hello,", name)
Field note
  • Python is case-sensitive
  • Comments start with #
03

Step 3 of 5

Variables and Input

Variables store data. The input() function gets user input.

python
# Variables
name = "John"
age = 25
height = 5.9

# User input
user_name = input("What is your name? ")
print(f"Hello, {user_name}!")

# Type conversion
age_str = input("Enter your age: ")
age = int(age_str)  # Convert string to integer
Field note
  • Use descriptive variable names
  • input() always returns a string
04

Step 4 of 5

Basic Math Operations

Python makes math easy with intuitive operators.

python
# Basic operations
addition = 10 + 5        # 15
subtraction = 10 - 5     # 5
multiplication = 10 * 5  # 50
division = 10 / 5        # 2.0
floor_division = 10 // 3 # 3
modulus = 10 % 3         # 1
exponent = 2 ** 3        # 8

# Calculator example
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
result = num1 + num2
print(f"Sum: {result}")
Field note
  • Use // for integer division
  • Use ** for exponentiation (not ^)
05

Step 5 of 5

String Formatting

Python offers multiple ways to format strings.

python
name = "Alice"
age = 30

# f-strings (recommended)
message = f"My name is {name} and I am {age} years old"

# .format() method
message = "My name is {} and I am {} years old".format(name, age)

# String concatenation
message = "My name is " + name + " and I am " + str(age)

print(message)
Field note
  • f-strings are the most readable and efficient
  • Convert numbers to strings with str()

Guide complete

You’ve got the method. Now make it yours.