编程中所面临的一个挑战就是给变量指定合适的名称,但不能是关键字或是内置函数。
1 关键字
这些关键字都有特殊的含义, 如果我们将它们用作变量名, 就会引发错误:
| 关键字 | 关键字 | 关键字 | 关键字 | 关键字 |
|---|---|---|---|---|
| False | class | finally | is | return |
| None | continue | for | lambda | try |
| True | def | from | nonlocal | while |
| and | del | global | not | with |
| as | elif | if | or | yield |
| assert | else | import | pass | |
| break | except | in | raise |
2 内置函数
如果我们将这些内置函数名用作变量名, 那么就会覆盖这些函数,从而改变它们的行为:
| 内置函数 | 内置函数 | 内置函数 | 内置函数 | 内置函数 |
|---|---|---|---|---|
| abs() | divmod() | input() | open() | staticmethod() |
| all() | enumerate() | int() | ord() | str() |
| any() | eval() | isinstance() | pow() | sum() |
| basestring() | execfile() | issubclass() | print() | super() |
| bin() | file() | iter() | property() | tuple() |
| bool() | filter() | len() | range() | type() |
| bytearray() | float() | list() | raw_input() | unichr() |
| callable() | format() | locals() | reduce() | unicode() |
| chr() | frozenset() | long() | reload() | vars() |
| classmethod() | getattr() | map() | repr() | xrange() |
| cmp() | globals() | max() | reversed() | zip() 和 Zip() |
| compile() | hasattr() | memoryview() | round() | __import__() |
| complex() | hash() | min() | set() | apply() |
| delattr() | help() | next() | setattr() | buffer() |
| dict() | hex() | object() | slice() | coerce() |
| dir() | id() | oct() | sorted() | intern() |
注意:
Python 2.x 中,print 是关键字而不是函数 。
Python 3.x 中,没有内置函数 unicode()。
作者:deniro
链接:https://www.jianshu.com/p/0f73f860c4f5
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
