六、python输入输出

六、python输入输出

1.输入

python里的input输入用法
name=input("what is your name: ")
age=input("what is your age: ") # input输入的直接就为str类型,不需要再str()转换了
print(name,"你"+age+"岁了")

2.输出

(1) 普通输出

print("="*10) 		# 表示连续打印10个=符号
print("1-系统")
print("2-数据库")
print("3-quit")
print("="*10)
或者
print("="*10)
print('''1-系统
2-数据库
3-quit''')		# 使用''' '''符号来换行
print("="*10)

image

(2) 格式化输出

操作符 说明
%s 字符串
%d 整数
%f 浮点数
%% 输出 %
name=input("what is your name: ")
age=input("what is your age: ")
num=int(input("what is your phone number: ")) # 因为iput输入的纯数字也是是str类型,所以用
int()转成int类型,这样才能在后面对应%d
print(name,"you are %s years old,and your phone number is %d"%(age,num)) # 按顺序对
应,age对应%s,num对应%d
name=input("what is your name: ")
age=input("what is your age: ")
num=int(input("what is your phone number: "))
# 下面这是一种新的格式化输出写法,不用去纠结是写%s还是%d,只对应好顺序就行.(0代表第一个,1代表第二个)
print(name,"you are {} years old, and your phone number is {}".format(age,num))
print(name,"you are {1} years old, and your phone number is {0}".format(num,age))
posted @ 2023-06-02 09:39  村尚chun叔  阅读(51)  评论(0编辑  收藏  举报