Docsity

Python Basics Cheat Sheet 2026 | Quick Revision Notes for Beginners, Cheat Sheet of Computer science

Partial preview of the text

Download Python Basics Cheat Sheet 2026 | Quick Revision Notes for Beginners and more Cheat Sheet Computer science in PDF only on Docsity!

Python Basics Cheat Sheet

1. Variables & Data Types

x = 10 # int

y = 3.14 # float

name = "Sagor" # string

is_active = True # bool

2. Operators

# Arithmetic

a + b, a - b, a * b, a / b, a % b

# Comparison

a == b, a != b, a > b, a < b

# Logical

a and b, a or b, not a

3. Control Flow

if-else

if x > 0: print("Positive")

else: print("Non-positive")

for loop

for i in range(5): print(i)

while loop

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

  1. Functions

def greet(name):

return f"Hello, {name}!"

print(greet("Sagor"))

5 .Lists & Dictionaries

# List

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

print(fruits[0]) # apple

# Dictionary

person = {"name": "Sagor", "age": 25}

print(person["name"]) # Sagor