Python programming for everyone, Study notes of Computer science

Python programming study notes PDF for college and school students. Includes important concepts, definitions, coding examples, and revision material for exams and assignments.

Typology: Study notes

2025/2026

Available from 05/20/2026

aman-khan-21
aman-khan-21 🇮🇳

1 document

1 / 75

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
🐍 PYTHON PROGRAMMING
Complete Notes • Class 6 • Absolute Beginner to Advanced
Step-by-step explanations with real-life examples
Every concept explained like you're 11 years old
Hundreds of code examples, tips, and exercises
Tables, diagrams, and memory tricks
Practice questions after every chapter
"Learning Python is like learning a superpower. Once you know it,
you can make computers do anything you want!"
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b

Partial preview of the text

Download Python programming for everyone and more Study notes Computer science in PDF only on Docsity!

🐍 PYTHON PROGRAMMING

Complete Notes • Class 6 • Absolute Beginner to Advanced

✅Step-by-step explanations with real-life examples

✅Every concept explained like you're 11 years old

✅Hundreds of code examples, tips, and exercises

✅Tables, diagrams, and memory tricks

✅Practice questions after every chapter

"Learning Python is like learning a superpower. Once you know it, you can make computers do anything you want!"

TABLE OF CONTENTS

Chapter 1: Introduction to Python

Chapter 2: Setting Up Python on Your Computer

Chapter 3: Your First Python Program

Chapter 4: Variables and Data Types

Chapter 5: Numbers and Math Operations

Chapter 6: Strings – Playing with Text

Chapter 7: Getting Input from the User

Chapter 8: Making Decisions – if / elif / else

Chapter 9: Loops – Doing Things Again and Again

Chapter 10: Lists – Storing Many Things

Chapter 11: Tuples – Unchangeable Lists

Chapter 12: Dictionaries – Key-Value Pairs

Chapter 13: Sets – Unique Collections

Chapter 14: Functions – Reusable Code Blocks

Chapter 15: Scope and Namespaces

Chapter 16: Modules and Imports

Chapter 17: File Handling – Reading & Writing Files

Chapter 18: Error Handling – try / except

Chapter 19: Object-Oriented Programming (OOP)

Chapter 20: Inheritance and Polymorphism

Chapter 21: Advanced Functions

Chapter 22: List Comprehensions & Generators

Chapter 23: Regular Expressions

Chapter 24: Working with Dates and Time

Chapter 25: Python Projects & Next Steps

CHAPTER 1

Introduction to Python

▶ What is Python?

Python is a programming language. A programming language is a special set of words and rules that

we use to give instructions to a computer. Just like we use English or Hindi to talk to people, we use

Python to talk to computers!

Python was created by a Dutch programmer named Guido van Rossum. He started working on it in

1989 and released it in 1991. He named it 'Python' not after the snake, but after a British comedy

TV show called 'Monty Python's Flying Circus' that he liked!

🐍 IMPORTANT: Python is one of the most popular programming languages in the world today.

Companies like Google, YouTube, Netflix, Instagram, Spotify, and NASA all use Python!

▶ Why Learn Python?

 🟢 Easy to read and write – Python looks almost like plain English

 🟢 Free to use – Anyone can download and use Python for free

 🟢 Works everywhere – Python works on Windows, Mac, and Linux

 🟢 Lots of uses – websites, games, science, AI, robots, and more

 🟢 Huge community – Millions of people use Python; help is always available

 🟢 Perfect for beginners – Best first language to learn

▶ What Can You Do With Python?

Area What Python Can Do Famous Example

Web Development Build websites and web apps Instagram, Pinterest Data Science Analyse huge amounts of data Used by scientists worldwide Artificial Intelligence Create smart programs ChatGPT uses Python Game Development Make fun games Many indie games

Automation Automate boring tasks Auto-fill forms, send emails Robotics Control robots NASA Mars Rover software Cybersecurity Find and fix security problems Ethical hacking tools Finance Analyse stocks and numbers Used by banks

▶ How Does a Computer Understand Python?

Computers only understand 0s and 1s (binary). So Python code cannot be directly understood by

the hardware. Python uses a special program called an Interpreter that reads your Python code line

by line and translates it into instructions the computer can follow.

🐍 ANALOGY: Think of the Python Interpreter as a live translator. Imagine you speak only Hindi,

and your friend speaks only English. A translator stands between you and converts your Hindi

words into English instantly, sentence by sentence. The Python interpreter does the same — it

converts your Python code into computer language instantly.

▶ Python Versions

There are two major versions of Python you will hear about:

Version Released Should You Use It? Notes

Python 2 2000 ❌NO Old version, no longer supported since 2020 Python 3 2008 ✅YES Current version. We use this in all our lessons

🐍 IMPORTANT: Always use Python 3. Python 2 is dead. All new projects use Python 3.

▶ Chapter 1 – Quick Quiz

1. Who created Python and when?

2. Why is Python called 'Python'?

3. Name 3 companies that use Python.

4. What does the Python Interpreter do?

5. Which version of Python should you use – Python 2 or Python 3? Why?

CHAPTER 2

Setting Up Python on Your Computer

▶ Step 1 – Download Python

6. Open your web browser (Chrome, Firefox, etc.)

7. Go to: www.python.org

8. Click on 'Downloads'

9. Click on the big yellow button that says 'Download Python 3.x.x'

10. Wait for the file to download

▶ Step 2 – Install Python (Windows)

11. Double-click the downloaded file

12. ⭐VERY IMPORTANT: Check the box that says 'Add Python to PATH' (This is at the bottom of

the installer window)

13. Click 'Install Now'

14. Wait for installation to finish

15. Click 'Close'

🐍 IMPORTANT: If you forget to check 'Add Python to PATH', Python will not work properly. You

will have to uninstall and reinstall it.

▶ Step 3 – Check If Python Is Installed

Open the Command Prompt (Windows) or Terminal (Mac/Linux) and type:

python --version

You should see something like:

Python 3.12.

🐍 TIP: On some computers you might need to type python 3 --version instead of python --version

▶ Understanding the Python Shell (IDLE)

Python comes with a built-in editor called IDLE (Integrated Development and Learning

Environment). Let's understand the two modes:

Mode What It Is How to Open Best For

Interactive Shell Type one line, see result instantly Open IDLE → Shell window opens Quick tests and experiments Script Mode Write a full program in a file File → New File in IDLE Writing complete programs

▶ Installing VS Code (Recommended Editor)

VS Code (Visual Studio Code) is a free, powerful code editor made by Microsoft. Most professional

programmers use it. Here's how to install it:

16. Go to code.visualstudio.com

17. Click 'Download for Windows' (or your operating system)

18. Install it like a normal program

19. Open VS Code

20. Go to Extensions (Ctrl+Shift+X)

21. Search for 'Python' and install the extension by Microsoft

🐍 TIP: VS Code makes coding much easier because it shows errors, suggests code as you type, and

highlights your code in colours!

▶ Online Python Editors (No Installation Needed!)

If you cannot install Python on your computer, you can use online editors:

Website Link Features

Replit replit.com Free, save your projects, share with others Python Anywhere pythonanywhere.com Free, runs Python in the cloud Online Python onlinepython.com Simple, instant, no sign-up needed Google Colab colab.research.google.com Great for science and AI projects

CHAPTER 3

Your First Python Program

▶ Hello, World!

By tradition, every programmer's first program is called 'Hello, World!'. It simply prints those

words on the screen. Here is how you do it in Python:

print("Hello, World!")

When you run this program, you will see:

Hello, World!

🐍 EXPLANATION: print() is a built-in Python function. A function is like a magic word that does

something for you. The print() function displays whatever you put inside the parentheses ( ) on the

screen.

▶ Understanding print()

The print() function can display many things:

print("Hello, World!") # prints text print(42) # prints a number print(3.14) # prints a decimal number print("I love Python!") # prints another message print() # prints a blank line

▶ What Are Comments?

In the code above, you saw lines starting with #. These are called COMMENTS. Comments are notes

that YOU write for yourself (or other programmers). Python completely ignores comments — they

are not executed.

This is a comment

Python will ignore this line

print('Hello') # This comment is at the end of a line

Comments help you remember what your code does

Always write clear comments!

🐍 TIP: Good programmers always write comments. Future-you will thank present-you when you

read your code 6 months later and still understand it!

▶ Single Quotes vs Double Quotes

In Python, you can use both single quotes (' ') and double quotes (" ") for text. They work the same

way!

print("Hello") # double quotes - works! print('Hello') # single quotes - also works!

Use double quotes when your text has an apostrophe:

print("I'm learning Python!") # need backslash OR use double quotes print("I'm happy!") # backslash before apostrophe

▶ Printing Multiple Things

Method 1: Use a comma to print multiple items

print("My name is", "Arjun") print("I am", 11, "years old")

Method 2: Combine strings with +

print("Hello " + "World")

Method 3: Print multiple lines

print("Line 1") print("Line 2") print("Line 3")

▶ Special Print Effects with Escape Characters

26. Print the following on one single line using end=: Hello My name is Python

CHAPTER 4

Variables and Data Types

▶ What is a Variable?

A variable is like a labelled box that stores a value. Imagine you have a box with 'Age' written on it,

and inside the box is the number 11. In Python, you can create such boxes and store values in them.

🐍 REAL LIFE ANALOGY: Think of a variable as a glass jar with a label. You can put anything in the

jar — water, juice, sand. The label tells you what's inside. In Python, the label is the variable name,

and the contents are the variable value.

▶ Creating Variables

Creating a variable in Python is very easy. You just write the name, then =, then the value:

Syntax: variable_name = value

name = 'Arjun' age = 11 height = 4. is_student = True

Print the variables

print(name) # Output: Arjun print(age) # Output: 11 print(height) # Output: 4. print(is_student) # Output: True

▶ Rules for Naming Variables

Not every word can be used as a variable name. Python has rules:

Rule Correct Wrong

Must start with a letter or _ name, _count, age1 1name, @age Can contain letters, digits, _ my_name, score2 my-name, my name

price = 99.99 # price pi = 3.14159 # famous mathematical constant weight = - 2.5 # negative float print(type(height)) # Output:

◆ 3. String (str) – Text

name = "Arjun" city = 'Mumbai' sentence = "I love Python programming!" empty = "" # empty string print(type(name)) # Output:

◆ 4. Boolean (bool) – True or False

is_student = True has_pet = False loves_coding = True print(type(is_student)) # Output:

Note: True and False must start with CAPITAL letters

true and false are WRONG in Python!

◆ 5. NoneType – No Value

None means 'nothing' or 'no value'

result = None print(result) # Output: None print(type(result)) # Output:

▶ The type() Function

The type() function tells you what data type a value is. This is very useful for debugging!

print(type(42)) # print(type(3.14)) # print(type("hello")) # print(type(True)) # print(type(None)) #

▶ Type Conversion (Casting)

Sometimes we need to change a value from one type to another. This is called type conversion or

casting:

int() - converts to integer

x = int("42") # string to int → 42 y = int(3.9) # float to int → 3 (truncates, doesn't round!) z = int(True) # bool to int → 1

float() - converts to float

a = float("3.14") # string to float → 3. b = float(5) # int to float → 5.

str() - converts to string

c = str(42) # int to string → '42' d = str(3.14) # float to string → '3.14'

bool() - converts to boolean

print(bool(1)) # True print(bool(0)) # False print(bool("")) # False (empty string) print(bool("hi")) # True (non-empty string)

🐍 IMPORTANT: When converting a float to int with int(), Python just cuts off the decimal part.

int(3.9) gives 3, NOT 4. Use round() if you want proper rounding!

▶ Multiple Assignment

Assign same value to multiple variables

x = y = z = 0 print(x, y, z) # 0 0 0

Assign different values in one line

a, b, c = 10, 20, 30 print(a) # 10 print(b) # 20 print(c) # 30

Swap two variables (very Pythonic!)

x = 5 y = 10

CHAPTER 5

Numbers and Math Operations

▶ Basic Arithmetic Operators

Operator Name Example Result Notes

  • Addition 5 + 3 8 Adds two numbers
  • Subtraction 10 - 4 6 Subtracts second from first
  • Multiplication 6 * 7 42 Multiplies two numbers / Division 10 / 3 3.333... Always gives a float! // Floor Division 10 // 3 3 Divides and rounds down % Modulo 10 % 3 1 Gives the remainder ** Exponentiation 2 ** 8 256 Raises to the power

▶ Understanding Each Operator

Addition

print(5 + 3) # 8 print(2.5 + 1.5) # 4.

Subtraction

print(10 - 4) # 6 print(5 - 8) # - 3

Multiplication

print(6 * 7) # 42 print(3 * 3.0) # 9.

Division (always returns float)

print(10 / 2) # 5.0 (not 5!) print(7 / 2) # 3.

Floor Division (rounds DOWN)

print(10 // 3) # 3 print(7 // 2) # 3

print(-7 // 2) # - 4 (rounds towards negative infinity)

Modulo (remainder)

print(10 % 3) # 1 (10 = 33 + 1) print(15 % 4) # 3 (15 = 43 + 3) print(8 % 2) # 0 (8 is perfectly divisible by 2)

Exponentiation (power)

print(2 ** 10) # 1024 print(3 ** 3) # 27 print(9 ** 0.5) # 3.0 (square root!)

▶ BODMAS / Order of Operations

Python follows the same BODMAS rules you learn in Maths class. This determines which operation

is calculated first when you have multiple operators in one expression.

Order Letter Stands For Example

1st B Brackets ( ) 2nd O Orders / Exponents ** (powers, roots) 3rd D Division / or // 3rd M Multiplication * 4th A Addition + 4th S Subtraction -

Without brackets

print(2 + 3 * 4) # 14 (3*4 first, then +2) print(10 - 6 / 2) # 7.0 (6/2 first, then 10 - 3)

With brackets (changes order!)

print((2 + 3) * 4) # 20 (2+3 first, then *4) print((10 - 6) / 2) # 2.0 (10-6 first, then /2)

Complex expression

result = 2 + 3 * 4 ** 2 / 8 - 1

Step 1: 4**2 = 16

Step 2: 3*16 = 48

Step 3: 48/8 = 6.

Step 4: 2+6.0 = 8.

Step 5: 8.0-1 = 7.

print(result) # 7.

▶ Useful Math Functions