震驚了!每30秒學會一個Python小技巧
- 2019 年 10 月 7 日
- 筆記
向大家推薦一個將碎片化時間利用到極致的github項目《30-seconds-of-python》

作者實現了List、Math、Object、Utility方面74個小函數,每個學習時間僅需30秒,而且每個實例都給出了思路、實現程式碼和example,以階乘為例:
Factorial(Calculates the factorial of a number)
Use recursion. If num is less than or equal to 1, return 1. Otherwise, return the product of num and the factorial of num – 1. Throws an exception if num is a negative or a floating point number.
def factorial(num): if not ((num >= 0) and (num % 1 == 0)): raise Exception( f"Number( {num} ) can't be floating point or negative ") return 1 if num == 0 else num * factorial(num - 1)
Examples
factorial(6) # 720
作者還建了一個網站,方便大家查找
https://github.com/30-seconds/30-seconds-of-python

此外,30秒學Python只是作者龐大計劃其中一支,還有CSS/PHP/React等方向值得大家去挖掘更多精彩!
30 seconds of Code
30 seconds of CSS
30 seconds of Interviews
30 seconds of Knowledge
30 seconds of React
30 seconds of PHP
項目地址
https://python.30secondsofcode.org
END