Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

A comprehensive Python cheatsheet for quick reference and learning

License

NotificationsYou must be signed in to change notification settings

onyxwizard/python-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀Welcome to the Python Learning Guide!
This repository is yourstep-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 – UseTrue andFalse, 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 (OOPS)

🧠 What You’ll Learn

This README provides a structured and beginner-friendly guide toObject-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.

  • 🧩 Useproperty() 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
  • 🚶 Usesuper() to delegate to parent
  • 🧱 Use__slots__ for memory efficiency
  • 🧻 Abstract base classes withabc.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 withenum.Enum
  • 🧷 Use@unique to prevent duplicate values
  • 🧮 Auto-generate values withauto()
  • 📦 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 usingtype()
  • 🧩 Define custom metaclasses
  • 🧱 Inject behavior via metaclass
  • 🧠 Usedataclass 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

🧮 Python Concurrency

⏱️Build high-performance & responsive Python applications using concurrency techniques.
🧠 Learn about multithreading, multiprocessing, and asynchronous programming to improve application performance and responsiveness.

📌 What You’ll Learn:

  • Build high-performance & responsive Python applications.
  • Develop multithreaded programs usingthreading.
  • Run parallel tasks usingmultiprocessing.
  • Understand single-threaded concurrency viaasyncio.

🧵Use threads for I/O-bound tasks.

  • 🧠Processes vs Threads – Understand differences and when to use each.
  • 🧵Threading module – Usethreading for concurrent thread execution.
  • 🧱Extending Thread class – Customize behavior by subclassingThread.
  • 💬Returning values from threads – Capture results safely.
  • 📈Multithreading Example – Scrape stock prices concurrently.
  • 🌙Daemon threads – Background threads that don’t block program exit.
  • 🧰Thread Pools – Efficiently manage threads usingThreadPoolExecutor.

🔐Avoid race conditions and ensure safe access.

  • 🧱Lock – Prevent simultaneous access to shared data.
  • 🚦Event – Communicate between threads (e.g., wait/signal patterns).
  • ⏹️How to stop a thread – Safely terminate child threads.
  • 🚧Semaphore – Control number of concurrent threads accessing a resource.

📦Exchange data safely across threads.

  • 🧷Thread-safe Queue – Usequeue.Queue for safe inter-thread communication.

🔌Run CPU-bound tasks in parallel using separate processes.

  • 🧲Multiprocessing module – Usemultiprocessing.Process to spawn new processes.
  • 🧰Process Pools – Manage processes efficiently usingPool orProcessPoolExecutor.

Write asynchronous, non-blocking code using coroutines.

  • 🧠Understanding Event Loop – Core of async programming; manages coroutine execution.
  • 🧶async/await – Define and await coroutines without blocking.
  • 🧩Creating Tasks – Schedule coroutines for execution.
  • 🚫Canceling Tasks – Cancel running tasks using.cancel().
  • Timeout-based Cancellation – Useasyncio.wait_for() to cancel after timeout.
  • 🕐asyncio.wait() – Run multiple awaitables concurrently.
  • 🎯Future – UnderstandFuture objects for eventual results.
  • 🧱Running multiple tasks concurrently with gather() – Run tasks concurrently usingasyncio.gather().

🎉Let’s learn Python together — one concept at a time!



[8]ページ先頭

©2009-2025 Movatter.jp