Skip to content

twtrubiks/python-notes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-notes

Python Notes 學習筆記 📝

介紹

有時候想找一個東西(寫法),但當下卻忘記關鍵字,所以整理一篇學習筆記,要找資料的時候也比較方便。

有些是網路上找的範例,然後自己再修修改改,或是去參考一些 Python-Patterns , Python Anti-Patterns 。

範例程式會盡量遵守 PEP 8 -- Style Guide for Python Code

歡迎大家一起討論~

筆記會持續更新~

筆記

global_tutorial.py - global tutorial

globals_tutorial.py - globals tutorial

repr_tutorial.py - repr tutorial

assert_tutorial.py - assert tutorial

str_find_tutorial.py - str_find tutorial

rjust_ljust_tutorial.py - str rjust ljust tutorial

attribute_obj.py - setattr() , getattr() , hasattr()

check_is_in_list.py - 檢查目標是否在 list 裡

datetime_tutorial.py - datetime , monthrange , timestamp

defaultdict_tutorial.py - defaultdict

counter_tutorial.py - counter

namedtuple_tutorial.py - namedtuple

dictionary_using_items.py - dictionary.items()

dictionary_get.py - dictionary get()

set_tutorial.py - set tutorial

dictionary_update.py - dictionary update()

tuple_tutorial.py - tuple

eafp.py - EAFP coding style

enumerate_tutorial.py - enumerate

filter.py - filter

format.py - format

function_default.py - function default value

isdigit.py - isdigit()

isinstance.py - check type

join.py - join

json_tutorial.py - json.loads()

convert_class_object_to_json.py

convert_json_to_class_object.py

kwargs.py - **kwargs , *arg - youtube tutorial - What is **kwargs *args

lambda.py - lambda

list_tutorial.py - list tutorial

loop_if_else_break.py - if not add break , will run more meaningless loop

map_tutorial.py - map tutorial

OrderedDict_tutorial.py - OrderedDict

MappingProxyType_tutorial.py - MappingProxyType

parse_dateutil.py - dateutil.parser

property_decorator.py - property_decorator

raise_an_exception_from_function_call.py - it is better to raise an exception that can be caught by the caller instead.

range.py - range

reduce.py - reduce

setdefault_tutorial.py - setdefault

sort.py - sort

sorted.py - sorted

iter_tutorial.py - iter tutorial

iter_another_trick_tutorial.py - iter another trick tutorial

iterator_in_tutorial - in 也會消費 iterator

__iter__tutorial - __iter__ tutorial

yield_tutorial.py- yield tutorial

yield_from_tutorial.py- yield from tutorial

Enum_tutorial.py- Enum tutorial

strtobool_tutorial.py - strtobool

underscore_variable.py - underscore variable

use_unpacking.py - use unpacking

using_a_mutable_default_value_as_an_argument.py - Be careful with mutable default arguments ( lists or dictionaries ) - youtube tutorial

zip_tutorial.py - zip

staticmethod_tutorial.py - staticmethod tutorial

classmethod_tutorial.py - classmethod tutorial

decorator_tutorial.py - decorator 裝飾器

decorator_inspect.py - decorator inspect tutorial

with_as_tutorial.py - with as tutorial

context_manager_tutorial.py - context manager

suppress_tutorial.py - context manager - suppress - youtube tutorial - python 教學 - 什麼是 suppress

configparser_tutorial - ConfigParser tutorial,可參考 https://docs.python.org/3/library/configparser.html

decimal_tutorial.py - decimal tutorial

copy_tutorial.py - copy_tutorial

sum_tutorial.py - sum_tutorial

math_tutorial.py - math_tutorial

built-in-functions_tutorial.py - Built-in Functions tutorial

division_operators_tutorial.py - division operators tutorial

reduce_use_for_loop_tutorial_1.py - reduce_use_for_loop_tutorial_1

reduce_use_for_loop_tutorial_2.py - reduce_use_for_loop_tutorial_2

nested_loop_tutorial.py - nested_loop_tutorial

dict.fromkeys_tutorial.py - dict.fromkeys tutorial

escape_tutorial.py - html.parser ( escape ) tutorial

urllib_parse_quote_tutorial.py - urllib.parse quote tutorial

pickle_tutorial.py - pickle tutorial

__reduce__tutorial.py - __reduce__ tutorial

zipfile_tutorial.py - zipfile tutorial

unicodedata_tutorial.py - unicodedata ( control character ) tutorial

translate_tutorial.py - translate tutorial

re_tutorial.py - re tutorial

fnmatch_tutorial - fnmatch tutorial

is_integer_tutorial.py - float is_integer tutorial ( TestCase )

remove_trailing_zeros_tutorial.py - decimal remove trailing zeros tutorial ( TestCase )

itemgetter_tutorial.py - itemgetter tutorial

groupby_tutorial.py - itertools groupby tutorial

groupby_tutorial_find_consecutive numbers.py - find consecutive numbers in list by groupby tutorial

python-decouple-tutorial - python decouple tutorial

dj_database_url_tutorial - dj-database-url tutorial ( for django )

pandas_tutorial - pandas tutorial

random_tutorial.py - random tutorial

__str__tutorial.py - __str__ tutorial

__len__tutorial.py - __len__ tutorial

__call__tutorial.py - __call__ tutorial - youtube tutorial - What is the __call__ in python

__getattr__tutorial.py - __getattr__ and __getattribute__ tutorial

__getitem__tutorial.py - __getitem__ and __setitem__ tutorial

__new__tutorial.py - __new__ tutorial

__get__tutorial.py - 參考 what_is_the_Descriptor

queue_tutorial.py - queue tutorial

methodcaller_tutorial - methodcaller tutorial - youtube tutorial - python 教學 - 什麼是 methodcaller

str_startswith_tutorial.py - str.startswith() tutorial

logging_tutorial.py - logging tutorial

operator_or_xor_tutorial.py - or xor tutorial

operator_add_tutorial.py - operator.add tutorial

operator_mul_tutorial.py - operator.mul tutorial

itertools_tutorial.py - itertools tutorial

itertools_islice_tutorial.py - itertools.islice tutorial

itertools_tee_tutorial.py - itertools.tee tutorial

base64_tutorial.py - base64 encode decode tutorial

bytesio_tutorial.py - bytesio tutorial

stringio_tutorial.py - stringio tutorial

string_constants_tutorial.py - string constants tutorial

functools_partial_tutorial.py - functools.partial tutorial

try_except_tutorial.py - try except tutorial

try_finally_tutorial.py - try except finally tutorial

user_defined_exceptions_tutorial.py - User-defined Exceptions tutorial

weakref_tutorial.py - weakref tutorial

hashlib_tutorial - hashlib (MD5 SHA-1 簽名) tutorial

bcrypt_tutorial.py - bcrypt hash salt tutorial

hmac_sha256_tutorial.py - hmac sha256 tutorial

pycryptodome_tutorial - pycryptodome 完成 RSA 簽名驗簽, RSA 加解密

aes_tutorial.py - pycryptodome 完成 AES CBC 加解密

pyjwt_tutorial - jwt 教學

pyotp - 實作 two-factor (2FA) or multi-factor (MFA)

assignment_expressions_tutorial - Youtube Tutorial - 海象運算符 PEP 572 – Assignment Expressions - python3

match_case_tutorial.py - match case statement was introduced in Python 3.10

dataclasses_tutorial.py - dataclasses tutorial

importlib_tutorial - 動態 import lib

mock_tutorial - mock 教學

redis_tutorial - redis 教學

pika_tutorial - pika for Rabbitmq 教學

thread_process_tutorial - thread, process 教學

concurrent_futures_tutorial - concurrent futures 教學

asyico_tutorial - asyico 教學

aiohttp_tutorial - aiohttp 教學

pathlib_tutorial.py - pathlib 教學

colorama_tutorial.py - 讓 python 輸出 terminal 有顏色

cachetools_tutorial.py - cachetools 教學

觀念

python_circular_import - youtube tutorial - What is Python Circular Imports

What happens when you type an URL in the browser and press enter - youtube tutorial - What happens when you type an URL in the browser and press enter

cap theorem - youtube tutorial - What is CAP theorem

what is the python decorator

what is the python property

what is the classmethod and staticmethod

what is the abstractmethod

what is the functools.lru_cache

what is the singledispatch

what is the singledispatchmethod

what is the if __name__ == '__main__' in python

what is private and protected attribute

what is the python interpreter

what is the f-string

what is the mixin

type-hints-tutorial - PEP 484 Type Hints 介紹 - youtube tutorial - PEP 484 Type Hints 介紹

pydantic_tutorial - pydantic 介紹

other

fibonacci numbers tutorial

data structure

linked list

binary_tree_traversal

graph

tools

vcr-tutorial - Youtube Tutorial - vcrpy 介紹教學 - 輕鬆把 request 錄下來

freezegun_tutorial.py - mock datetime

faker_tutorial.py - 產生假資料

decorator_lib.py - decorator lib tutorial

pytest_tutorial - pytest 教學

flake8 - linter 工具

black - 自動排版工具

isort - 排序 import 套件

pipx - 類似 linux 中的 apt, 更方便管理套件. - youtube tutorial - python 套件介紹

指定 python 版本

pipx install --python python3.8 flake8

查看目前安裝套件

pipx list

commitizen and pre-commit - 規格化 commit 以及 pre-commit

pip-audit - 檢查 packages 安全性.

首先, 不要用 sudo/admin 下載 packages.

pip install pip-audit

使用方法很簡單, pip-audit --fix 直接幫你更新有問題的 packages.

pyenv - 更好用的 python 管理虛擬環境工具(管理多版本)

pip-tools_tutorial - 幫你管理依賴套件的版本

如何使用

基本上,每個 python 檔案都可以直接執行。

python xxxx.py

範例

python defaultdict_tutorial.py

執行環境

  • Python 3.9

Reference

Donation

文章都是我自己研究內化後原創,如果有幫助到您,也想鼓勵我的話,歡迎請我喝一杯咖啡:laughing:

綠界科技ECPAY ( 不需註冊會員 )

alt tag

贊助者付款

歐付寶 ( 需註冊會員 )

alt tag

贊助者付款

贊助名單

贊助名單

License

MIT license

Releases

No releases published

Packages

No packages published

Languages