前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >震惊了!每30秒学会一个Python小技巧

震惊了!每30秒学会一个Python小技巧

作者头像
统计学家
发布2019-09-26 15:31:08
4340
发布2019-09-26 15:31:08
举报

向大家推荐一个将碎片化时间利用到极致的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

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-09-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 机器学习与统计学 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Factorial(Calculates the factorial of a number)
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档