向大家推荐一个将碎片化时间利用到极致的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
添加微信,我们在微信群接着聊
推荐阅读