0% found this document useful (0 votes)
2 views

Python Cheat Sheet

This document is a comprehensive Python cheat sheet covering basic syntax, data types, input/output, operators, conditional statements, loops, functions, data structures, file handling, exception handling, and importing libraries. It also includes mini project ideas and a 30-day learning roadmap. Additionally, it suggests practicing using Replit or installing Python from python.org.

Uploaded by

raymond786666
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)
2 views

Python Cheat Sheet

This document is a comprehensive Python cheat sheet covering basic syntax, data types, input/output, operators, conditional statements, loops, functions, data structures, file handling, exception handling, and importing libraries. It also includes mini project ideas and a 30-day learning roadmap. Additionally, it suggests practicing using Replit or installing Python from python.org.

Uploaded by

raymond786666
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
You are on page 1/ 4

PYTHON FULL CHEAT SHEET (Beginner to Intermediate)

1. Basic Syntax

# This is a comment

print("Hello World")

2. Variables and Data Types

name = "John" # String

age = 25 # Integer

price = 19.99 # Float

is_online = True # Boolean

3. Input and Output

username = input("Enter your name: ")

print("Hello,", username)

4. Operators

# Math: +, -, *, /, %, //, **

# Comparison: ==, !=, >, <, >=, <=

# Logical: and, or, not

5. Conditional Statements

age = 18

if age >= 18:

print("You are an adult.")

else:
print("You are a minor.")

6. Loops

For Loop:

for i in range(5):

print(i)

While Loop:

count = 0

while count < 5:

print(count)

count += 1

7. Functions

def greet(name):

print("Hello", name)

greet("John")

8. Data Structures

List:

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

Dictionary:

person = {"name": "John", "age": 30}

Tuple:

coordinates = (10, 20)

Set:
numbers = {1, 2, 3, 4}

9. File Handling

Write:

file = open("test.txt", "w")

file.write("Hello World")

file.close()

Read:

file = open("test.txt", "r")

print(file.read())

file.close()

10. Exception Handling

try:

age = int(input("Enter age: "))

print(100 / age)

except ZeroDivisionError:

print("Cannot divide by zero.")

except ValueError:

print("Invalid input.")

finally:

print("Done.")

11. Importing Libraries

import math

print(math.sqrt(16))
12. Mini Project Ideas

- Calculator

- To-Do App

- Password Generator

- Quiz Game

- File Organizer

Roadmap (30 Days Plan)

Week 1: Basics

Week 2: Data structures and functions

Week 3: Mini projects

Week 4: Libraries + Final project

Practice Tip:

Use Replit or install Python from python.org!

You might also like