# 注释语法'#'空格一下'''多行注释'''"""多行注释"""
import keyword
在变量中使用 \
语法:\ 使用反斜杠
案例:
total_one = 1total_tow = 2total_three = 3total = total_one + \total_tow + \total_threeprint(total)
type():查看类型 str = 字符串 int = 整数 float = 小数 bool = 布尔值 list = 列表 tuple = 元祖 dict = 字典 set = 集合
%d
student = 1print('我的学号是%06d' % student)# 输出:我的学号是000001
%.1f 保留一位小数点,多个变量语法糖 % (1,2,3)
price = 9.00weight = 5.0money = price * weightprint('商品单价是%.1f,商品重量是%.1fkg,总价是%.2f元' % (price,weight,money))# 输出:商品单价是9.0元,商品重量是5.0kg,总价是45.00元
%s
userName = '小明'sheName = '小红'print('我的名字是%s,她的名字是%s' % (userName,sheName))# 输出我的名字是小明,她的名字是小红
\n 换行 \r 回车 \t 水平制表符 \b 退格 \\ 反斜杠 \' 单引号 \" 双引号整型 int(变量) 浮点型 float(变量) 字符串 str(变量) 布尔型 boll(变量)input('输入些什么')
name = input('输入姓名')print(name)# 输出 输入姓名 注释:只有输入姓名以后才会往下执行
if 条件:passelse:pass
if 条件A:passelse if条件B:passelse:pass...
import sysfor i in sys.argv:print(i)print('python路径为',sys.path)from sys import argv,path# 从sys模块中中导入path函数print('python路径为',path)
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号