网站顶部轮播怎么做的,h5网站开发中心,网站获取访客qq号码,xx单位网站建设方案1.输出
print(Hello, World!)
2.退出命令提升符
exit()
3.Python 缩进 实例
if 5 2:print(Five is greater than two!) 空格数取决于程序员#xff0c;但至少需要一个。 您必须在同一代码块中使用相同数量的空格#xff0c;否则 Python 会…1.输出
print(Hello, World!)
2.退出命令提升符
exit()
3.Python 缩进 实例
if 5 2:print(Five is greater than two!) 空格数取决于程序员但至少需要一个。 您必须在同一代码块中使用相同数量的空格否则 Python 会出错 错误实例
if 5 2:print(Five is greater than two!) print(Five is greater than two!)
4.Python 中的注释 a.行注释
#This is a comment.
print(Hello, World!) b.块注释 This is a comment
written in
more than just one lineprint(Hello, World!)
5.变量
a.与其他编程语言不同Python 没有声明变量的命令。
b.变量不需要使用任何特定类型声明甚至可以在设置后更改其类型。
x 5 # x is of type int
x Steve # x is now of type str
print(x) 输出只有Steve
c.字符串变量可以使用单引号或双引号进行声明
x Bill
# is the same as
x Bill
d.变量名称
变量可以使用短名称如 x 和 y或更具描述性的名称age、carname、total_volume。
Python 变量命名规则
变量名必须以字母或下划线字符开头变量名称不能以数字开头变量名只能包含字母数字字符和下划线A-z、0-9 和 _变量名称区分大小写age、Age 和 AGE 是三个不同的变量
请记住变量名称区分大小写
e.向多个变量赋值
Python 允许您在一行中为多个变量赋值
x, y, z Orange, Banana, Cherry
print(x)
print(y)
print(z)
输出
Orange
Banana
Cherryf.输出变量
如需结合文本和变量Python 使用 字符
字符字符
x awesome
print(Python is x)
输出
Python is awesome数字数字
x 5
y 10
print(x y)
输出
15不能字母数字
错误实例
x 10
y Bill
print(x y)
输出
Traceback (most recent call last):File E:\py脚本\zxpy自学python_01.py, line 3, in moduleprint(x y)~~^~~
TypeError: unsupported operand type(s) for : int and strg.全局变量
实例
在函数外部创建变量并在函数内部使用它
x awesomedef myfunc():print(Python is x)
myfunc()
输出
Python is awesomeh.局部变量
在函数内部创建一个与全局变量同名的变量
x awesome
def myfunc():x fantasticprint(Python is x)
myfunc()
print(Python is x)
输出
Python is fantastic
Python is awesomej.global 关键字
通常在函数内部创建变量时该变量是局部变量只能在该函数内部使用。
要在函数内部创建全局变量您可以使用 global 关键字。
如果您用了 global 关键字则该变量属于全局范围
x 222111def myfunc():global xx fantasticmyfunc()print(Python is x)
输出
Python is fantastic写博客总结标题要从标题二开始这样更加清楚明了