春秋网,水野紫苑,霍启仁antonia
变量(variables):
是为了存储程序在运算过程中的一些中间结果,为了方便日后调用储存在计算的内存中
官方介绍:
variables are used to storeinformation to be referenced and manipulated in a computer program.
they alsoprovidea way of labeling data with a descriptive name, so our programs can be understoodmore clearly by the reader and ourselves.
it is helpful to think of variables as containers that hold information(如果我们把变量看作成是一个保存信息的容器是更容易理解的).
their sole purpose is to label and store data in memory. this data can then be used throughout your program.
常量 :
不变的量
eg. π = 3.141592653...(在 python 中 π 用 pi 表示)
注意:在python中所有的变量都是可变的 ,所以用全部大写的变量名来代表次变量为常量
变量的命名规则:
1. 要具有描述性
2. 变量名只能_,数字,字母组成,不可以是空格或特殊字符(#?<.,¥$*!~)
3. 不能以中文为变量名
4. 不能以数字开头
5. 保留字符是不能被使用
6. 当需要用两个或以上的单词来进行命名时:
eg. 使用下划线区分单词 :student_number =
驼峰式命名(首字母不能大写):studentnumber =
7. 不可以用关键字作为变量名
#关键字:指令或有特殊含义的词汇 (eg.print )
格式化方法:format()
format(变量1,变量2)
变量1 对应{0} 变量2 对应{1}
注意:python从0开始计数,意味着索引中的第一位是0,第二位是1
age = 20
name = alex
print({1} : {0} .format(age,name))
如果上述内容有错漏之处或者有疑问的地方,欢迎大家一起指出,一起学习!!!
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
python如何查看网页代码
用python查看网页代码的方法:1、使用“import”导入requests包import requests2、使用requests包的get()函数通过网页...
[阅读全文]
-
-
python如何保存文本文件
python保存文本文件的方法:使用python内置的open()类可以打开文本文件,向文件里面写入数据可以用write()函数,写完之后,使用close()函...
[阅读全文]
-
python如何编写win程序
python可以编写win程序。win程序的格式是exe,下面我们就来看一下使用python编写exe程序的方法。编写好python程序后py2exe模块即可将...
[阅读全文]
-
-
-
-
-
-
网友评论