Skip to content

prspth/python-cheat-sheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

The Only Python Cheat Sheet You Will Ever Need

🐍 Python Cheat Sheet

A concise and practical cheat sheet, covering over 95% of all Python 3.x commands with examples. Designed for both Python developers, learners, and hobbyists. It provides quick answers and efficient learning without overwhelming you with details. This cheat sheet summarizes key Python syntax, concepts, and common functions in a compact PDF format.


πŸ“₯ Download

πŸ“„ Download the Python Cheat Sheet (PDF)


πŸ“š Topics Covered

  • 🧠 Data Types & Data Type Conversions
  • πŸ”€ Booleans & Strings
  • βž— Operator Precedence
  • πŸ–¨οΈ Print Functions & πŸ§‘β€πŸ’» User Input
  • πŸ”„ Decision Structure
  • πŸ” Repetition Structures
  • ⚠️ Exceptions
  • πŸ“ Files & Strings
  • 🧰 Functions & Modules
  • 🧡 List, Dict, Set, Tuple

Cheat Sheet Page 1

Data Types

  • Text Type: str
  • Numeroc Type: int, float, complex
  • Boolean Type: bool
  • Sequence Types: List (list), Tuple (tuple), Range (range)
  • Set Type: Set (set)
  • Mapping Type: Dictionary (dic)

Data Type Conversions

  • Integer and Float Conversions: float(), int()
  • Real to Complex Data Type Conversion: complex()
  • Data Type Conversion with Strings: int(), str()
  • Type Conversion to Tuples and Lists: tuple(), list()
  • Type Conversion to Dictionaries and Sets: set(), dict()
  • Convert Binary to Decimal: bin(), int()
  • Convert Hexadecimal to Decimal: hex(), int()
  • Convert Text to Decimal: ord(), chr()

Booleans

  • Booleans as Numbers
  • Comparison Operators: ==, !=, <, >, <=, >=
  • Membership and Identity Operators: in, not in, is, is not
  • Boolean Operators: not, and, or
  • Operator Precedence

Print Function

  • print(), sep and end parameters

User Input

  • input()

Decision Structure

  • if-then-elif-else statements

Repetition Structures

  • while statement
  • for statement

Exceptions

  • FileNotFoundError, IndexError, KeyError, ModuleNotFoundError, NameError, SyntaxError, TypeError, ValueError, ZeroDivisionError

Modules

  • import statement
  • from... import statement

Files

  • open(), close(), read(), readline(), readlines()
  • access modes: read, write, append, create

Strings

  • String Delimiters: single quotes, double quotes, triple single quotes, triple double quotes
  • Escape Sequences
  • String Operations: concatenation, repetition
  • String Length: len()
  • Unicode Code/Text Conversion: ord(), chr()
  • String Membership: in, not in
  • String Indexing
  • String Slicing
  • String Slicing Steps
  • String Methods: upper(), lower(), isupper(), islower(), count(), endswith(), find(), index(), isalnum(), isalpha(), isdecimal(), isdigit(), isnumeric(), strip(), rstrip(), lstrip(), split(), replace()
  • Iterating over Strings

Cheat Sheet Page 2

Lists

  • List Creation: list()
  • List Comprehension
  • List Indexing
  • List Slicing
  • List Length: len()
  • List Membership: in, not in
  • List Comparison: ==, !=, <, >, <=, >=
  • List Manipulation
  • List Concatenation and Repetition
  • Adding Elements: append(), extend(), insert()
  • Removing Elements: remove(), pop()
  • Deleting Elements: del
  • List Counting, Searching, and Sorting: count(), index(), reverse(), sort()
  • String-to-List and Back: split(), join()
  • List Built-in Functions: all(), any(), len(), list(), max(), min(), reversed(), sorted(), sum(), tuple(), zip()
  • Iterating over Lists

Tuples

  • Tuple Creation: tuple()
  • Tuple Unpacking
  • Tuple Built-in Functions: all(), any(), count(), enumerate(), filter(), index(), len(), list(), map(), max(), min(), next(), reversed(), slice(), sum(), sorted(), tuple(), zip()
  • Tuple Operations: indexing, slicing, concatenation, repetition, membership
  • Iterating over Tuples

Sets

  • Set Creation: set()
  • Adding Elements: add(), update()
  • Removing Elements: remove(), discard()
  • Set Operations: union, intersection, difference, symmetric difference, subset, superset
  • Iterating over Sets

Dictionaries

  • Dictionary Creation: dict()
  • Dictionary Length: len()
  • Key Membership: in, not in
  • Retrieving a Value Given a Key: get()
  • Adding a Key/Value Pair
  • Updating a Key/Value Pair
  • Deleting a Key/Value Pair: del()
  • Dictionary Methods: get(), items(), keys(), pop(), popitem(), update(), clear()
  • Iterating over Dictionaries

Similarities & Differences

  • Ordered
  • Duplicates allowed
  • Mutable
  • Comparison
  • Access elements
  • Slicing
  • Concatenation, Repetition
  • Iteration

🚫 License

This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).

You are free to:

  • Share β€” copy and redistribute the material
  • Adapt β€” remix, transform, and build upon it

Under the following terms:

  • Attribution β€” You must give appropriate credit
  • NonCommercial β€” You may not use the material for commercial purposes

πŸ™Œ Contributions

Feel free to suggest improvements or open an issue. Contributions are welcome!


πŸ‘¨β€πŸ’» Author

Promethee Spathis
GitHub β€’ LinkedIn

About

The only python cheat sheet you will ever need.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published