Python History
-
Python was created by Guido van Rossum in 1989 at CWI (Centrum Wiskunde & Informatica) in Netherlands.
-
The first version of Python, Python 1.0, was released in 1991.
-
Guido wanted a language that was simple, easy to read, and powerful.
-
The name “Python” came from Guido’s favorite TV show “Monty Python’s Flying Circus”, not from the snake.
-
Later, improved versions were released:
-
Python 2.0 in 2000
-
Python 3.0 in 2008
-
-
Python 3 became the main version used worldwide because it is more modern and supports better features.
In short:
Python was created by Guido van Rossum in 1989 to make programming simple and readable for everyone.
Python:
Python is a simple and powerful programming language used to give instructions to the computer.
Python Program:
A Python program is a set of instructions written in Python to perform a specific task.
String:
A string is a collection of characters written inside single (' ') or double (" ") quotes. Strings are immutable.
List:
A list is a collection of items written inside square brackets [ ]. Lists are mutable.
Tuple:
A tuple is a collection of items written inside round brackets ( ). Tuples are immutable.
Mutable:
Mutable means something that can be changed after creation.
Immutable:
Immutable means something that cannot be changed after creation.
Chapter 8 – Loops in Python
Recalling Conditional Statements
In Python, a condition (शर्त) is a statement that can be either true (सही) or false (गलत).
Conditional statements help to check a condition and run only that part of the program which meets the condition.
Types of Conditional Statements
Example Program – Checking Grades
Explanation (व्याख्या):
-
The program asks the user to enter marks.
-
It checks the range of marks using if, elif, and else conditions.
-
Depending on the marks, it prints the correct grade.
What are Loops
Sometimes in programming, we need to repeat (दोहराना) a set of statements many times.
For this, we use loops.
A loop is an arrangement that repeats some steps until a given condition becomes false (गलत).
Example
If your teacher says “Write ‘I will study daily’ 10 times,”
instead of writing it 10 times manually, a loop can do it automatically.
Concept of a Counter
A counter (गिनने वाला variable) keeps track of how many times something happens in a loop.
Syntax:
or
Example
Output:
Explanation:
The variable counter starts from 1 and increases by 1 after every print until it reaches 5.
Iteration or Looping
Iteration (दोहराव) means repeating the same steps again and again until a condition is true.
To make a loop, we define three values:
-
Start value (प्रारंभिक मान) – where the loop begins.
-
Test condition (जाँच की शर्त) – the condition that must be true to continue.
-
Increment or Decrement value (बढ़ाना या घटाना) – how much the value changes each time.
While Loop Syntax
Output:
Explanation:
The loop starts from 0 and continues printing numbers until i becomes 10.
More While Loop Programs
Program 1 – Reverse Order (10 to 1)
Output:
Program 2 – Print Name Five Times
Output:
For Loop
The for loop is used to repeat (दोहराना) a set of instructions for a fixed number of times.
Syntax:
Example
Output:
Membership Operators
Membership operators are used to test whether a value is part of a list or not.
| Operator | Purpose |
|---|---|
| in | Checks if a value exists in a list. |
| not in | Checks if a value does not exist in a list. |
Example
Example Program – Using ‘in’ Operator
Output:
The range() Function
The range() function helps to create a list of numbers in order.
It is often used with the for loop.
Syntax:
Meaning of Parameters
-
Start value (शुरुआती मान) – where the list begins.
-
Stop value (अंत मान) – where the list ends (not included).
-
Step value (अंतर) – the difference between two numbers.
Example
Output:
Program – Printing Odd and Even Numbers
Program – Fibonacci Series
A Fibonacci Series (फिबोनाची श्रेणी) is a sequence where each number is the sum of the previous two numbers.
Output:
Explanation:
The program starts with 0 and 1, then keeps adding the previous two numbers to get the next one.
Applying Condition with for Loop
We can use if or if…else statements inside a for loop to apply conditions.
Syntax:
Using break Statement
The break statement is used to stop the loop before it finishes completely.
Example
Output:
New Terms
| Term | Meaning |
|---|---|
| Iteration or Looping | Repeating a set of instructions many times. |
| Iterative Statements | Commands used to create loops like while and for. |
| Counter Variable | A variable that keeps count of how many times a loop runs. |
| Membership Operators | Operators such as in and not in that check if a value exists in a list. |