Python basic cheatsheet¶
- Python Naming Rule
- Using
__future__
backport features - Check object attributes
- Define a function
__doc__
- Check instance type
- Check, Get, Set attribute
- Check inheritance
- Check all global variables
- Check callable
- Get function/class name
__new__
&__init__
- The diamond problem
- Representations of your class behave
- Break up a long string
- Get list item SMART
- Get dictionary item SMART
- Set a list/dict SMART
set
operations- NamedTuple
__iter__
- Delegating Iteration- Using Generator as Iterator
- Emulating a list
- Emulating a dictionary
- Emulating a matrix multiplication
- Decorator
- Decorator with arguments
- for: exp else: exp
- try: exp else: exp
- Lambda function
- Option arguments - (*args, **kwargs)
type()
declare (create) aclass
- Callable object
- Context Manager -
with
statement - Using
@contextmanager
- Using
with
statement open file - Reading file chunk
- Property - Managed attributes
- Computed attributes - Using property
- Descriptor - manage attributes
@staticmethod
,@classmethod
- Abstract method - Metaclass
- Common Use Magic
- Parsing csv string
- Using annotation to check type