向大家推荐一个将碎片化时间利用到极致的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
此外,30秒学Python只是作者庞大计划其中一支,还有CSS/PHP/React等方向值得大家去挖掘更多精彩!