2.Python:与用户交互

# 接受用户的输入
# username = input("请输入账号:")
# print(username, type(username))
#
# age = input("请输入年龄:") # input输入的内容为字符串类型
# print(age, type(age))
#
# x = int(age) # int()将纯数字的字符转换成整型

# ------------------------------------------------
# 格式化输出
# 1.按照位置传值
# %s 可以接收任意类型数据
# %d 只能接收int型
# 按照位置与%s一一对应
res1 = "my name is %s my age is %s" % ("SEPIA", "32")
print(res1)

# 通过字典传值
res2 = "my name is %(name)s my age is %(age)s" % {'name': 'SEPIA', 'age': '32'}
print(res2)

# 2.按照key = value传值
res3 = "my name is {name} my age is {age}".format(age=32, name="SEPIA")
print(res3)

# 3.f
x = input('name:')
y = input('age:')
res4 = f'my name is {x} my age is {y}'
print(res4)
posted @ 2021-06-25 11:15  SEPIA  阅读(44)  评论(0)    收藏  举报