Python for Beginners – Complete Tutorial for Students

Python is the most beginner-friendly programming language and essential for engineering students, data science, and competitive programming. This complete guide takes you from zero to writing your first programs.

Why Learn Python?

  • Easy to Learn: Simple, readable syntax similar to English
  • High Demand: Used in AI, Data Science, Web Development, Automation
  • Career Opportunities: Python developers earn ₹6-15 LPA starting salary
  • Academic Use: Required for CBSE Class 11-12, Engineering courses
  • Versatile: One language for multiple domains

Setting Up Python

  1. Download Python from python.org
  2. Install with “Add Python to PATH” checked
  3. Open Command Prompt/Terminal and type python --version
  4. Use IDLE (comes with Python) or VS Code for writing code

Your First Python Program

# This is a comment
print("Hello, World!")
print("Welcome to Python Programming")

Output:

Hello, World!
Welcome to Python Programming

Variables and Data Types

# Variables - storing data
name = "Rahul"           # String (text)
age = 17                 # Integer (whole number)
height = 5.8             # Float (decimal)
is_student = True        # Boolean (True/False)

# Printing variables
print("Name:", name)
print("Age:", age)
print("Height:", height)

Basic Operations

# Arithmetic Operations
a = 10
b = 3

print(a + b)   # Addition: 13
print(a - b)   # Subtraction: 7
print(a * b)   # Multiplication: 30
print(a / b)   # Division: 3.333...
print(a // b)  # Floor Division: 3
print(a % b)   # Modulus (remainder): 1
print(a ** b)  # Power: 1000

Taking User Input

# Getting input from user
name = input("Enter your name: ")
age = int(input("Enter your age: "))

print("Hello", name)
print("You will be", age + 1, "next year")

Conditional Statements (if-else)

# Check if student passed
marks = int(input("Enter marks: "))

if marks >= 90:
    print("Grade: A+")
elif marks >= 80:
    print("Grade: A")
elif marks >= 70:
    print("Grade: B")
elif marks >= 60:
    print("Grade: C")
elif marks >= 33:
    print("Grade: D - Pass")
else:
    print("Grade: F - Fail")

Loops – Repeating Code

# For loop - repeat known times
for i in range(1, 6):
    print("Count:", i)

# While loop - repeat until condition
count = 1
while count <= 5:
    print("Count:", count)
    count = count + 1

# Print multiplication table
num = 7
for i in range(1, 11):
    print(num, "x", i, "=", num * i)

Lists – Storing Multiple Values

# Creating a list
fruits = ["Apple", "Banana", "Orange", "Mango"]

print(fruits[0])      # First item: Apple
print(fruits[-1])     # Last item: Mango
print(len(fruits))    # Length: 4

# Adding and removing
fruits.append("Grapes")    # Add at end
fruits.remove("Banana")    # Remove item

# Loop through list
for fruit in fruits:
    print(fruit)

Functions – Reusable Code

# Defining a function
def greet(name):
    print("Hello,", name, "!")
    print("Welcome to Python")

# Calling the function
greet("Priya")
greet("Amit")

# Function with return value
def add_numbers(a, b):
    return a + b

result = add_numbers(5, 3)
print("Sum:", result)

Practice Problems for Beginners

  1. Write a program to check if a number is even or odd
  2. Calculate the factorial of a number
  3. Print Fibonacci series up to n terms
  4. Check if a string is palindrome
  5. Find the largest of three numbers
  6. Create a simple calculator (+, -, *, /)
Learning Path:
  1. Variables, Data Types, Operators (Week 1)
  2. Conditionals, Loops (Week 2)
  3. Lists, Strings, Functions (Week 3-4)
  4. File Handling, Modules (Week 5-6)
  5. OOP Concepts (Week 7-8)

Continue Your Programming Journey

Explore more resources for engineering and computer science students.

More Programming Tutorials →

Python Fundamentals: Key Concepts for Beginners

Variables and Data Types

Python is dynamically typed — you do not need to declare the type of a variable:

  • int: Integers — age = 18
  • float: Decimal numbers — gpa = 8.5
  • str: Strings — name = “Priya”
  • bool: True or False — is_student = True
  • list: Ordered, mutable collection — marks = [90, 85, 78]
  • tuple: Ordered, immutable — coordinates = (12.9, 77.6)
  • dict: Key-value pairs — student = {“name”: “Raj”, “roll”: 42}
  • set: Unordered unique values — unique_marks = {90, 85, 78}

Control Flow

  • if-elif-else: Conditional logic
  • for loop: Iterate over sequences — for i in range(10): print(i)
  • while loop: Repeat while condition is true
  • break, continue, pass: Loop control statements

Functions

Functions help reuse code. Defined with the def keyword:

def calculate_average(marks): return sum(marks) / len(marks)

  • Parameters and return values
  • Default arguments: def greet(name, greeting=”Hello”)
  • *args and **kwargs for variable arguments
  • Lambda functions: square = lambda x: x**2

Object-Oriented Programming (OOP)

  • Class: Blueprint for objects
  • Object: Instance of a class
  • __init__: Constructor method
  • self: Reference to the current instance
  • Inheritance: Child class inherits parent class attributes and methods
  • Encapsulation: Private attributes (_var or __var)

File Handling

  • Open a file: f = open(“notes.txt”, “r”)
  • Read: f.read() or f.readlines()
  • Write: open(“notes.txt”, “w”)
  • Best practice: Use “with open” to auto-close files

Python Career Paths for Students

  • Data Science / ML: NumPy, Pandas, Scikit-learn, Matplotlib, Seaborn, TensorFlow/PyTorch
  • Web Development: Django (full-featured framework), Flask (lightweight)
  • Automation / Scripting: Selenium (browser automation), Requests (HTTP), BeautifulSoup (web scraping)
  • Backend APIs: FastAPI (modern, fast REST APIs), Flask
  • DevOps: Python scripts for cloud automation, Ansible, Boto3 (AWS SDK)

Python Practice Resources

  • Python.org official tutorial — start here for syntax fundamentals
  • HackerRank Python Domain — 100 practice problems from beginner to hard
  • LeetCode — data structures and algorithm problems in Python
  • Kaggle Learn — free Python and data science courses with built-in notebooks
  • Automate the Boring Stuff with Python (free online book) — practical real-world projects

Leave a Reply

Your email address will not be published. Required fields are marked *