ITPub博客

首页 > IT职业 > IT图书 > 说说 Python 关键字与内置函数

说说 Python 关键字与内置函数

IT图书 作者:ywbair 时间:2021-09-09 10:23:09 0 删除 编辑

图片描述

编程中所面临的一个挑战就是给变量指定合适的名称,但不能是关键字或是内置函数。

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


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2056/viewspace-2821320/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-16

  • 博文量
    84
  • 访问量
    666