gto76/python-cheatsheet

Public

Comprehensive Python Cheatsheet

  • Stars38.8k+75 tuần này
  • Forks6.7k
  • Watchers953
  • Issues0
  • Ngày tạo25/01/2018
  • Cập nhật gần nhất29/07/2026
  • Ngôn ngữPython
  • Giấy phép—
README.md320.0 KBRaw

Comprehensive Python Cheatsheet

Download text file, Fork me on GitHub or Check out FAQ.

Monty Python

Contents

    1. Collections:         List, Dictionary, Set, Tuple, Range, Enumerate, Iterator, Generator.
    2. Data Types:         Type, String, Regular_Exp, Format, Numbers, Combinatorics, Datetime.
    3. Syntax Rules:      Function, Inline, Import, Decorator, Class, Duck_Type, Enum, Except.
    4. System Calls:      Exit, Print, Input, Command_Line_Arguments, Open, Path, OS_Commands.
    5. Data Formats:     JSON, Pickle, CSV, SQLite, Bytes, Struct, Array, Memory_View, Deque.
    6. Misc Topics:        Operator, Match_Statement, Logging, Introspection, Threads, Asyncio.
    7. Pip Packages:     Progress_Bar, Plot, Table, Console_App, GUI, Scraping, Web, Profile.
    8. Multimedia:         NumPy, Image, Animation, Audio, Synthesizer, Pygame, Pandas, Plotly.

Main

if __name__ == '__main__':      # Skips indented lines of code if file was imported.
    main()                      # Executes user-defined `def main(): ...` function.

List

<list> = [<el>, <el>, ...]      # Creates new list object. E.g. `list_a = [1, 2, 3]`.
<el>   = <list>[index]          # First index is 0, last -1. Also `<list>[i] = <el>`.
<list> = <list>[<slice>]        # Also <list>[from_inclusive : to_exclusive : ±step].
<list>.append(<el>)             # Appends element to the end. Or `<list> += [<el>]`.
<list>.extend(<coll>)           # Appends collection's items. Or `<list> += <coll>`.
<list>.sort()                   # Sorts in ascending order. Accepts `reverse=True`.
<list>.reverse()                # Reverses the order of elements. Takes linear time.
<list> = sorted(<coll>)         # Returns a new sorted list. Accepts `reverse=True`.
<iter> = reversed(<list>)       # Returns reversed iterator. Also list(<iterator>).
<el>  = max(<coll>)             # Returns the largest element. Also min(<el>, <el>).
<num> = sum(<coll>)             # Returns a sum of elements. Also math.prod(<coll>).
elementwise_sum  

Nội dung README thuộc về gto76 và cộng đồng đóng góp, giấy phép Không có giấy phép. Nguồn: github.com/gto76/python-cheatsheet