0% found this document useful (0 votes)
5 views3 pages

Class10 Python Cheatsheet

This document is a quick reference guide for Python programming, covering essential topics such as print statements, lists, loops (for and while), and conditional statements (if/elif/else). It provides examples for each topic to illustrate their usage and includes tips for writing effective code. The guide emphasizes proper indentation, meaningful variable names, and logical flow in programming.
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)
5 views3 pages

Class10 Python Cheatsheet

This document is a quick reference guide for Python programming, covering essential topics such as print statements, lists, loops (for and while), and conditional statements (if/elif/else). It provides examples for each topic to illustrate their usage and includes tips for writing effective code. The guide emphasizes proper indentation, meaningful variable names, and logical flow in programming.
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 Practical Quick Sheet

1️⃣ print() Statements


Main Points: - Print text, numbers, or both - Use commas or + for concatenation - Use quotes for strings
( " " or ' ' )

Example:

print("Python is fun") # Text


print(5) # Number
print("Score:", 100) # Text + Number

2️⃣ Lists
Main Points: - Create: list_name = [] or list_name = [ ] - Add: .append() - Remove:
.remove() - Insert: .insert(index, element) - Combine: + or .extend() - Iterate using for

Example:

fruits = ["apple", "banana", "cherry"]


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

3️⃣ for Loops


Main Points: - Loop over a range or list - Can calculate sum, product, or apply conditions - Syntax: for i
in range(start, end, step):

Example (sum & even numbers):

sum = 0
for i in range(2, 11, 2): # Even numbers 2 to 10
sum = sum + i
print("Sum of even numbers =", sum)

1
4️⃣ while Loops
Main Points: - Repeats until condition is False - Initialize counter before loop - Update counter inside loop

Example (factorial):

num = int(input("Enter a number: "))


fact = 1
i = 1
while i <= num:
fact = fact * i
i = i + 1
print("Factorial =", fact)

5️⃣ if / elif / else


Main Points: - Check conditions - Use % for even/odd - Compare numbers for largest/smallest - Logical
operators: and , or , not - == for comparison, = for assignment

Example (largest of 3 numbers + even/odd check):

a = int(input("Enter 1st number: "))


b = int(input("Enter 2nd number: "))
c = int(input("Enter 3rd number: "))

if a > b and a > c:


largest = a
elif b > a and b > c:
largest = b
else:
largest = c

print("Largest number =", largest)

if largest % 2 == 0:
print("It is Even")
else:
print("It is Odd")

6️⃣ Combined List + Condition Example


Main Points: - Loop through a list - Apply condition inside loop - Count / sum / print based on condition

2
Example (even numbers in list):

numbers = [12, 7, 9, 20, 5, 14]


for i in numbers:
if i % 2 == 0:
print(i)

✅ Tips for Full Marks

• Indent properly
• Use meaningful variable names
• Initialize sum/product outside loop
• Check logic before typing
• For practical: think loop → condition → action

You might also like