chinesehuazhou / python-whydo Goto Github PK
View Code? Open in Web Editor NEWExplore Python's charms by asking WHY questions
Home Page: https://pythoncat.top
Explore Python's charms by asking WHY questions
Home Page: https://pythoncat.top
函数重载指的是有多个同名的函数,但是它们的签名或实现有不同。
Python 中使用装饰器(例如 functools 库的 singledispatch),可以实现函数重载的效果。
然而,原生 Python 语法层面不支持函数重载。
初步原因:locals 命名空间中不允许出现同名函数
TODO:语言设计时的考虑?相关历史讨论线索?
print(1)返回值为None,那1是什么意思?1不是返回值嘛?
👍
用法介绍
设计的讨论?
PEP-598 设计说明
https://peps.python.org/pep-0498/
问题:
1.起源于哪里?(其它语言?独创设计?)
2.其它语言的相同设计对比?
例如,条件表达式可能算吧?其它语言将条件放在前面,只有Python把一个值放在前面
例如,任意对象可做真值判断,也可能是首创
问题灵感:
@古明地觉https://mp.weixin.qq.com/s/fPmo14sBZXJgEUodTL7y1g
Python 在变量查找的时候遵循 LEGB 规则,也就是按照本地作用域、闭包、全局作用域、内置作用域的顺序。然而,列表解析式有自己的本地作用域,并不使用函数或者类的作用域!!
1.为什么py3会这样?
2.为什么py3和py2的行为不一样?
也称为 自由函数
脱离类/对象而存在,与其他面向对象语言的设计不同
过程式编程设计的影响?
1.内置函数/类型,分类讨论,不能一概而论
2.设计来源
Python 为什么没有 main 函数?为什么我不推荐写 main 函数? 中将java/C#归为编译型语言,个人感觉不恰当。这两者跟python一样,都是基于虚拟机的解释型语言。只是C#/java的解析器没python灵活,必须指定一个入口点。
在2020年5月“Python为什么”系列开篇之际,我发起过一份问卷调查,意图收集读者们感兴趣的话题。
到此时(2022.12)为止,共有32份问卷。感谢这些读者的反馈!
但是,这些问卷提交的时间跨度太长了(上个月刚好有一份),导致我未能及时查看和响应。另外,由于问卷系统缺乏交互,对于描述不清的内容,我理解不了却无法发起追问。
因此,我决定关闭问卷调查,后续将在 issues 处理相关问题。
读者已提交而未处理的问卷,我将整理后在此跟进处理。如果你曾提交过问卷调查却未有解答,烦请在这里重新提交!
写的很好,很有助于提升python功力,衷心表示感谢!
False,None,0,空序列,空字典
1.c语言,0值为假,非0值为真
2.Perl所有空值为假(空字符串,空列表,空哈希),非空值为真
3.Ruby false,nil,0 为假,其它值为真
三元运算符格式(也作 三目运算符):
条件表达式?表达式1:表达式2
Python有实现同样效果的条件表达式写法:
表达式1 if 条件表达式 else 表达式2
问题:
为什么不采用“?:”这种语法格式的设计?
已知线索:
条件表达式写法是2.5版本才引入的
help wanted:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.