Documentation

Comprehensive reference guide for Python and Pygame. Learn programming concepts, syntax, and see practical examples for game development.

If Statements

Make decisions in code based on conditions

Example

if age >= 18:
    print("You can vote!")
else:
    print("Too young to vote")

Elif Statements

Chain multiple conditions together

Example

score = 85

if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
else:
    grade = "F"
    
print(f"Your grade is: {grade}")

Ternary Operator

Compact way to write simple if-else statements

Example

age = 20
status = "adult" if age >= 18 else "minor"
print(status)  # Output: adult

# Multiple ternary operators
result = "positive" if x > 0 else "zero" if x == 0 else "negative"