Skip to content

onyxwizard/python-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Python Learning Repository

๐Ÿš€ Welcome to the Python Learning Guide!
This repository is your step-by-step roadmap to mastering Python โ€” from the basics to advanced topics. Whether you're a beginner or looking to sharpen your skills, this guide has got you covered.

๐Ÿ“˜ Each section builds on the previous one, so you can follow along in order or jump straight into the topic you need.


๐Ÿ”น Learn the basic structure and syntax of Python code.

  • ๐Ÿ”ค Variables โ€“ Understand how variables work and how to name them meaningfully.
  • ๐Ÿ“œ Strings โ€“ Work with text data and perform common string operations.
  • ๐Ÿงฎ Numbers โ€“ Explore integers and floating-point numbers.
  • ๐Ÿšฆ Booleans โ€“ Use True and False, and understand truthy and falsy values.
  • ๐Ÿ›‘ Constants โ€“ Learn how to define constants (by convention).
  • ๐Ÿ’ฌ Comments โ€“ Add notes and explanations inside your code.
  • ๐Ÿ” Type conversion โ€“ Convert between types like strings, integers, and floats.

๐Ÿ› ๏ธ Learn to manipulate data using operators.

  • โž• Arithmetic operators โ€“ Perform math operations (+, -, *, /, etc.)
  • โœ๏ธ Assignment operators โ€“ Assign and update variable values efficiently.
  • ๐Ÿ” Comparison operators โ€“ Compare two values (==, !=, <, >, etc.)
  • ๐Ÿง  Logical operators โ€“ Combine conditions (and, or, not)

๐Ÿง  Make decisions and control how your code runs.

  • โ“ ifโ€ฆelse statement โ€“ Run code based on conditions.
  • ๐ŸŽฏ Ternary operator โ€“ Write compact conditionals.
  • ๐Ÿ” for loop with range() โ€“ Loop for a set number of times.
  • โณ while loop โ€“ Repeat while a condition is true.
  • ๐Ÿ”š break โ€“ Exit a loop early.
  • โญ๏ธ continue โ€“ Skip current iteration and continue looping.
  • ๐ŸชŸ pass โ€“ Placeholder when no action is needed.

๐Ÿงฉ Write reusable blocks of code.

  • ๐Ÿ“Œ Python functions โ€“ Define and call functions.
  • ๐Ÿ“ฅ Default parameters โ€“ Set default values for arguments.
  • ๐Ÿ“ Keyword arguments โ€“ Make function calls more readable.
  • ๐Ÿ” Recursive functions โ€“ Call functions within themselves.
  • ๐ŸงŠ Lambda Expressions โ€“ Create small anonymous functions.
  • ๐Ÿ“„ Docstrings โ€“ Document your functions clearly.

๐Ÿ“‚ Work with ordered collections of data.

  • ๐Ÿ“ฅ List โ€“ Store and manipulate multiple items.
  • ๐Ÿช Tuple โ€“ Immutable lists that stay constant.
  • ๐Ÿงน Sort a list in place โ€“ Modify a list directly.
  • ๐Ÿงผ Sorted function โ€“ Get a new sorted list.
  • ๐Ÿงฉ Slice a List โ€“ Extract parts of a list.
  • ๐Ÿ“ฆ Unpack a list โ€“ Assign elements to variables.
  • ๐Ÿ” Iterate over a List โ€“ Loop through items.
  • ๐Ÿ” Find index of an element โ€“ Locate where something is.
  • ๐Ÿ”„ Map, Filter, Reduce โ€“ Transform and filter list elements.
  • ๐Ÿ’ก List comprehensions โ€“ Create lists quickly and cleanly.

๐Ÿ—‚๏ธ Section 6: Dictionaries

๐Ÿ—„๏ธ Use key-value pairs to organize data.

  • ๐Ÿ“ Dictionary โ€“ Store data as keys and values.
  • ๐Ÿงฐ Dictionary comprehension โ€“ Build dictionaries dynamically.

๐Ÿ”ข Section 7: Sets

๐Ÿงฎ Work with unique collections of items.

  • ๐Ÿ”’ Set โ€“ Store unique values.
  • ๐Ÿงฑ Set comprehension โ€“ Create sets concisely.
  • โˆช Union, Intersection, Difference โ€“ Combine and compare sets.
  • โІ Subset, Superset, Disjoint sets โ€“ Check relationships between sets.

๐Ÿ›ก๏ธ Handle errors gracefully and keep your programs running.

  • ๐Ÿ›‘ tryโ€ฆexcept โ€“ Catch and handle exceptions.
  • ๐Ÿงน tryโ€ฆexceptโ€ฆfinally โ€“ Always run cleanup code.
  • โœ… tryโ€ฆexceptโ€ฆelse โ€“ Run code only if no error occurs.

๐Ÿ” Advanced looping techniques.

  • ๐Ÿ” forโ€ฆelse โ€“ Run code after a loop finishes normally.
  • โณ whileโ€ฆelse โ€“ Run code after a while loop ends.
  • ๐Ÿ” doโ€ฆwhile emulation โ€“ Simulate doโ€ฆwhile behavior in Python.

๐Ÿ”ง Master advanced function features.

  • ๐Ÿ“ฆ Unpacking tuples โ€“ Assign tuple values to variables.
  • ๐Ÿ“ฅ *args Parameters โ€“ Accept any number of positional arguments.
  • ๐Ÿ“ *kwargs Parameters โ€“ Accept any number of keyword arguments.
  • ๐Ÿ”ง Partial functions โ€“ Fix some arguments for reuse.
  • ๐Ÿ“ Type hints โ€“ Improve readability and enable static type checking.

๐Ÿงฑ Organize and reuse your code effectively.

  • ๐Ÿ“„ Modules โ€“ Split code into separate files.
  • ๐Ÿ” Module search path โ€“ Understand how Python finds modules.
  • ๐Ÿง  name variable โ€“ Control script vs module behavior.
  • ๐Ÿ“ Packages โ€“ Organize modules into folders.
  • ๐Ÿ”’ Private functions โ€“ Hide internal implementation.

๐Ÿ“‚ Read from and write to files.

  • ๐Ÿ“– Read from a text file
  • โœ๏ธ Write to a text file
  • ๐Ÿ“„ Create a new text file
  • ๐Ÿ” Check if a file exists
  • ๐Ÿ“Š Read and write CSV files
  • ๐Ÿ—‘๏ธ Rename and delete files

๐Ÿ“ Interact with your file system.

  • ๐Ÿ“ Working with directories
  • ๐Ÿ” List files in a directory

๐Ÿ”ค Advanced string manipulation.

  • ๐ŸŽž๏ธ F-strings โ€“ Embed variables directly in strings.
  • ๐ŸงŠ Raw strings โ€“ Avoid escape character issues.
  • ๐Ÿงฑ Backslash usage โ€“ Handle special characters.

๐Ÿ“ฆ Install and manage external libraries.

  • ๐Ÿ“ฆ PyPI & pip โ€“ Install packages from the Python Package Index.
  • ๐Ÿงบ Virtual Environments โ€“ Isolate project dependencies.
  • ๐Ÿ’ป Install pipenv on Windows โ€“ Manage virtual environments easily.

๐Ÿงฌ Object-Oriented Programming in Python (OOP)

๐Ÿง  What Youโ€™ll Learn

This README provides a structured and beginner-friendly guide to Object-Oriented Programming (OOP) in Python. It's based on your uploaded content and includes:

  • ๐Ÿ”น Classes & Objects
  • ๐Ÿ”น Instance vs Class Variables
  • ๐Ÿ”น __init__() method
  • ๐Ÿ”น Private attributes
  • ๐Ÿ”น Static methods
  • ๐Ÿ”น Inheritance
  • ๐Ÿ”น Special methods (__str__, __repr__, etc.)
  • ๐Ÿ”น Property management
  • ๐Ÿ”น Exceptions in OOP

Each concept is explained with code examples and best practices for writing clean, maintainable object-oriented code.

๐Ÿง‘โ€๐Ÿ’ป Build your first class and understand object-oriented programming.

  • ๐Ÿงฑ Class definition and instance creation
  • ๐Ÿ“ฆ Instance vs class variables
  • ๐Ÿ” Private attributes and name mangling
  • ๐Ÿ› ๏ธ Constructor __init__()
  • ๐Ÿงฉ Instance methods and static methods
  • ๐Ÿงพ Method overloading via default and keyword arguments
  • ๐Ÿ’ก Best practices for readable OOP

๐Ÿง  Customize class behavior using special methods.

  • ๐Ÿ–จ๏ธ __str__ โ€“ user-friendly output
  • ๐Ÿงพ __repr__ โ€“ unambiguous representation
  • โœ… __eq__ โ€“ define equality logic
  • ๐Ÿ”ข __hash__ โ€“ make objects hashable
  • ๐Ÿšซ __bool__ โ€“ define truthiness
  • ๐Ÿ—‘๏ธ __del__ โ€“ handle object destruction

๐Ÿ—๏ธ Control access to internal attributes.

  • ๐Ÿงฉ Use property() to create properties
  • ๐ŸŽ€ Use @property decorator
  • ๐Ÿ“ฅ Getter, setter, and deleter patterns
  • ๐Ÿ“ Read-only properties
  • ๐Ÿง  Best practices for encapsulation

๐Ÿ‘จโ€๐Ÿ‘ฆ Learn inheritance and extend functionality.

  • ๐Ÿงฌ Single inheritance โ€“ class Child(Parent)
  • ๐Ÿ” Override methods
  • ๐Ÿšถ Use super() to delegate to parent
  • ๐Ÿงฑ Use __slots__ for memory efficiency
  • ๐Ÿงป Abstract base classes with abc.ABC

๐Ÿงฌ Understand method resolution order and mixin classes.

  • ๐Ÿง  Implement multiple inheritance
  • ๐Ÿงญ MRO โ€“ Pythonโ€™s method lookup strategy
  • ๐Ÿงฉ Mixin classes for cross-cutting concerns
  • ๐Ÿšซ Avoid diamond problem with proper design
  • ๐Ÿงฒ Combine behaviors without deep hierarchies

๐Ÿ”ข Represent fixed sets of constants.

  • ๐Ÿงฑ Define enums with enum.Enum
  • ๐Ÿงท Use @unique to prevent duplicate values
  • ๐Ÿงฎ Auto-generate values with auto()
  • ๐Ÿ“ฆ Extend custom enum classes
  • ๐Ÿง  Use enums instead of hardcoded strings

๐Ÿ› ๏ธ Apply SOLID principles for maintainable designs.

  • ๐Ÿ“ฆ Single Responsibility Principle
  • ๐Ÿงฉ Open/Closed Principle
  • ๐Ÿ”„ Liskov Substitution Principle
  • ๐Ÿ“ Interface Segregation Principle
  • ๐Ÿง  Dependency Inversion Principle

๐Ÿ”— Reuse attribute access logic with descriptors.

  • ๐Ÿง  Descriptor protocol โ€“ __get__, __set__, __delete__
  • ๐Ÿ“ฆ Data vs non-data descriptors
  • ๐Ÿงฉ Reusable validation and computed properties
  • ๐Ÿงฑ Descriptor examples: type checking, lazy loading

๐Ÿ”ฎ Modify or generate code at runtime.

  • ๐Ÿงฌ Use __new__ to control object creation
  • ๐Ÿ“ฆ Dynamically create classes using type()
  • ๐Ÿงฉ Define custom metaclasses
  • ๐Ÿงฑ Inject behavior via metaclass
  • ๐Ÿง  Use dataclass to auto-generate boilerplate

โš™๏ธ Handle errors within object-oriented contexts.

  • ๐Ÿง  Raise exceptions in methods
  • ๐Ÿงฉ Create custom exception classes
  • ๐Ÿ›ก๏ธ Catch and propagate exceptions
  • ๐Ÿงน Graceful error recovery in OOP
  • ๐Ÿ“ฆ Exception best practices in real applications

๐ŸŽ‰ Letโ€™s learn Python together โ€” one concept at a time!