Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

onyxwizard/python-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 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.

🗄️ Use key-value pairs to organize data.

  • 📁 Dictionary – Store data as keys and values.
  • 🧰 Dictionary comprehension – Build dictionaries dynamically.

🧮 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!


Morty Proxy This is a proxified and sanitized view of the page, visit original site.