# 声明变量 区分大小写 name = "andy" age = 18 print(name,age) temp = type(2 ** 64) # type检测变量类型 print(temp)
# 查看关键字 import keyword print(keyword.kwlist)
# 字符串拼接 name = "andy" age = 18 six = "男" print(name + six) # 字符串拼接用+ print(name * 10) # 字符串运算 10个 andy
# input函数的使用 获取用户输入的内容 字符串类型的 password = input("请输入密码:") print("输入的内容是:" + password)
# 类型转换 temp = int("520") # 字符串转换成整型 print(type(temp)) temp2 = float("12.5") print(type(temp2))
# 字符串格式化输出 name = "张三" age = 18 price = 12.052 student_no = 1 scale = 0.25 print("我的名字是%s" % name) # 字符使用%s print("今年%d岁" % age) # 整数使用%d print("价格是%.2f" % price) # 小数使用%f 保留小数点2位中间.2 print("学生编号是%06d" % student_no) # 整数最低6位 不足6位补0 print("数据比例是%.2f%%" % (scale* 100)) # 输出百分号使用%%
# 字符串格式化输出2 name = "张三" age = 18 price = 100.25 print("我的名字是%s,年龄%d岁,能卖%.2f元" % (name,age,price))
原文:https://www.cnblogs.com/dazahui/p/14843318.html