0% found this document useful (0 votes)
2 views10 pages

Python Beginner Notes

This document is a beginner's workbook for learning Python programming, covering essential topics such as variables, data types, loops, functions, and error handling. It includes explanations, examples, practice questions, and mini projects to reinforce learning. The workbook encourages hands-on practice by typing out examples and attempting exercises.

Uploaded by

1981 SidraJamil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Python Beginner Notes

This document is a beginner's workbook for learning Python programming, covering essential topics such as variables, data types, loops, functions, and error handling. It includes explanations, examples, practice questions, and mini projects to reinforce learning. The workbook encourages hands-on practice by typing out examples and attempting exercises.

Uploaded by

1981 SidraJamil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming

Beginner Notes & Practice Workbook

Level: Complete Beginner

Purpose: Learn Python step by step through simple explanations, examples, questions, and mini projects.

How to use these notes


Read one topic, type the examples yourself, then attempt the practice questions without looking at the
answers.

Python Beginner Notes • Page 1


Contents
1 Introduction to Python

2 First Python Program

3 Variables and Data Types

4 Input and Output

5 Operators

6 Conditional Statements

7 Loops

8 Strings

9 Lists, Tuples and Dictionaries

10 Functions

11 Error Handling

12 Practice Questions

13 Mini Projects

Python Beginner Notes • Page 2


1. Introduction to Python
Python is a high-level, general-purpose programming language. It is popular because its syntax is
readable and it can be used for automation, websites, data science, artificial intelligence, and many other
tasks.

Examples
# This is a comment
print("Hello, Python!")

Key points
• Python is case-sensitive: name and Name are different.

• Comments begin with # and are ignored when the program runs.

• Indentation (spaces at the beginning of a line) is important in Python.

Try it yourself
1. What is a programming language?

2. Why is Python considered beginner-friendly?

3. Write a one-line comment in Python.

2. Your First Python Program


The print() function displays information on the screen.

Examples
print("Hello World!")
print("I am learning Python.")
print(10 + 5)

Key points
• Text is usually written inside quotation marks.

• Numbers can be used directly in calculations.

Try it yourself
1. Print your name.

2. Print your school name.

3. Print the result of 25 + 17.

3. Variables and Data Types


A variable is a name used to store a value. Common beginner data types are int (whole numbers), float
(decimal numbers), str (text), and bool (True/False).

Examples
name = "Ali"
age = 14
height = 5.6

Python Beginner Notes • Page 3


student = True

print(name)
print(age)
print(type(height))

Key points
• int: 10, 25, -3

• float: 3.14, 5.5

• str: "Python", "Hello"

• bool: True or False

Try it yourself
1. Create variables for your name, age, and favorite subject.

2. What data type is 25?

3. What data type is "25"?

4. What data type is 4.5?

4. Input and Output


input() allows the user to enter information. Input is normally received as text, so use int() or float() when
you need a number.

Examples
name = input("Enter your name: ")
print("Hello", name)

age = int(input("Enter your age: "))


print("Next year you will be", age + 1)

Key points
• input() gets information from the user.

• int() converts text to a whole number.

• float() converts text to a decimal number.

Try it yourself
1. Ask the user for their favorite color and print it.

2. Ask for two numbers and print their sum.

5. Operators
Operators are symbols used to perform calculations and comparisons.

Examples
a = 10
b = 3
print(a + b) # addition

Python Beginner Notes • Page 4


print(a - b) # subtraction
print(a * b) # multiplication
print(a / b) # division
print(a // b) # floor division
print(a % b) # remainder
print(a ** b) # power

Key points
• Comparison operators: ==, !=, >, <, >=, <=

• Logical operators: and, or, not

• Assignment operators include =, +=, -=, *=.

Try it yourself
1. Calculate the area of a rectangle.

2. Check whether 20 is greater than 15.

3. Find the remainder when 29 is divided by 4.

6. Conditional Statements
Conditional statements let a program make decisions. Python uses if, elif, and else.

Examples
marks = 75

if marks >= 50:


print("Pass")
else:
print("Fail")

age = 18
if age >= 18:
print("Adult")
elif age >= 13:
print("Teenager")
else:
print("Child")

Key points
• The condition is tested after if.

• Use elif for another condition.

• Use else when none of the earlier conditions is true.

• The indented lines belong to the condition.

Try it yourself
1. Write a program that checks whether a number is positive or negative.

2. Write a program that prints Grade A for marks 80 or above and Grade B otherwise.

7. Loops

Python Beginner Notes • Page 5


Loops repeat instructions. The for loop is useful when you know what you want to repeat; while repeats
while a condition remains true.

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

count = 1
while count <= 5:
print(count)
count += 1

Key points
• range(1, 6) produces 1, 2, 3, 4, 5.

• A while loop must eventually change its condition to avoid running forever.

Try it yourself
1. Print numbers 1 to 10 using for.

2. Print even numbers from 2 to 20.

3. Use a while loop to print 5, 4, 3, 2, 1.

8. Strings
A string is a sequence of characters. Python provides many useful string operations.

Examples
text = "Python Programming"
print([Link]())
print([Link]())
print(len(text))
print(text[0])
print(text[0:6])

Key points
• Indexing starts at 0.

• upper() changes letters to uppercase.

• lower() changes letters to lowercase.

• len() returns the number of characters.

Try it yourself
1. What is the first character of "Computer"?

2. Find the length of "Pakistan".

3. Convert "hello" to uppercase.

9. Lists, Tuples and Dictionaries


Collections allow you to store multiple values. A list can be changed, a tuple is generally used for fixed
values, and a dictionary stores key-value pairs.

Python Beginner Notes • Page 6


Examples
fruits = ["apple", "banana", "mango"]
[Link]("orange")
print(fruits)
print(fruits[1])

point = (10, 20)


print(point)

student = {"name": "Sara", "age": 13}


print(student["name"])

Key points
• Lists use square brackets [ ].

• Tuples use parentheses ( ).

• Dictionaries use curly braces { } and key-value pairs.

Try it yourself
1. Create a list of five subjects.

2. Add an item to a list.

3. Create a dictionary containing a student's name and age.

10. Functions
A function is a reusable block of code. Functions help keep programs organized and reduce repetition.

Examples
def greet(name):
print("Hello", name)

greet("Ayesha")

def add(a, b):


return a + b

result = add(5, 7)
print(result)

Key points
• def starts a function definition.

• Parameters receive values.

• return sends a value back to the place where the function was called.

Try it yourself
1. Create a function that prints your school name.

2. Create a function that multiplies two numbers.

3. Create a function that checks whether a number is even.

11. Basic Error Handling

Python Beginner Notes • Page 7


Programs sometimes encounter invalid input or other errors. try and except can prevent a program from
stopping unexpectedly.

Examples
try:
number = int(input("Enter a number: "))
print(number * 2)
except ValueError:
print("Please enter a valid whole number.")

Key points
• try contains code that may cause an error.

• except handles a specified type of error.

Try it yourself
1. What happens if int() receives non-numeric text?

2. Write a program that safely asks for a number.

Python Beginner Notes • Page 8


12. Practice Questions
1. Write a program to print your name, class, and school.

2. Create two variables and print their sum.

3. Take two numbers from the user and print their product.

4. Write a program to check whether a number is even or odd.

5. Print numbers from 1 to 20 using a for loop.

6. Print the multiplication table of 5.

7. Find the largest of two numbers using if/else.

8. Create a list of five fruits and print each fruit using a loop.

9. Create a function that calculates the area of a rectangle.

10. Create a dictionary containing a student's name, class, and age.

13. Mini Projects


1. Simple Calculator
Ask the user for two numbers and an operation (+, -, *, /), then display the result.

2. Marks Calculator
Take marks for several subjects, calculate the total and average, and display a simple grade.

3. Number Guessing Practice


Choose a number in your program and let the user make guesses. Give simple higher/lower hints.

4. Multiplication Table Generator


Ask for a number and print its table from 1 to 10.

5. Student Information Program


Ask for a student's name, class, and age, store them in a dictionary, and display the information.

Quick Revision
Concept Remember

print() Displays output

input() Gets user input

variable Stores a value

if / elif / else Makes decisions

for / while Repeats instructions

list Stores multiple changeable values

dictionary Stores key-value pairs

Python Beginner Notes • Page 9


def Creates a function

return Sends a value back from a function

Beginner tip: Don’t just read Python code—type it, run it, change it, and see what happens. Practice is the
fastest way to learn programming.

Python Beginner Notes • Page 10

You might also like