python基础---变量

子曰:学而时习之,不亦说乎

1.何为变量

变量好比一个"容器",可以存储与之相关联的东西。

message = "Hello Python world!"
print(message)

上述代码中message就是一个“容器”,而"Hello Python world!"就是需要存储的数据,通过print()方法可以把容器里的东西展示打印出来。

2.变量的命名

  • 变量名只能包含字母、数字、下划线,可以以字母或下划线开头,不能以数字开头。
  • 变量名不能包含空格,但是可以用下划线来分隔其中的单词。
  • 不要将Python关键字和函数名用作变量(见下方附录)。
  • 变量名应即简短又具有描述性(中文名称转换变量名称)。
  • 慎用小写字母‘l’和大写字母‘O’,它们可能被人错看成数字1和0.

python关键字

-
False class finally is return
None comtinue for lambda try
True def from nonlocal white
and del global not with
as elif if or yield
assert else import pass
break except in raise

python内置函数

-
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()python2.7的函数
chr() frozenset() long() reload() vars()
classmethod getattr map() repr() xrange()
cmp() globals() max() reversed() 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()

猜你喜欢

转载自www.cnblogs.com/mo-he/p/10869308.html