python01 用户交互程序
标签(空格分隔): 编程语言 Python
input
input用来赋值变量不确定的值
Input对应的输入都当做字符串
Int(input):将input输入的字符串强制转成数字
%s字符串 占位符
%d数字 占位符
%f浮点数 占位符
1.使用%s拼接
name = input ('name:')
age = input ('age:')
info = '''
-----information of %s----- #这里%s用来站位,后面指定站位的内容
Name:%s
Age:%s
------------end------------
''' %(name,name,age) #一共有3个%s占位符,根据先后顺序指定占位符的内容
print (info)下面是输出结果:
name和age,都是不确定的值,自己手动输入什么就是什么。
2.使用{}拼接
2.1
name = input ('name:')
age = input ('age:')
info = '''
-----information of {_name}-----
Name:{_name}
Age:{_age}
------------end------------
''' .format(_name=name,_age=age)
print (info)使用大括号{}也可以当做占位符,然后通过.format来引用变量

2.2
name = input ('name:')
age = input ('age:')
info = '''
-----information of {0}-----
Name:{0}
Age:{1}
------------end------------
''' .format(name,age)
print (info)
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦

