您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
name = input("name:")
age = input("age:")
job = input("job:")
message = '''
---------information of ''' + name +'''----------
name:''' + name + '''
age:''' + age + '''
job:''' + job
print(message)
----------information of zhoumingkang----------
name:zhoumingkang
age:30
job:it
Process finished with exit code 0
name = input("name:")
age = int(input("age:")) #强制将字符串转为×××
print(type(age)) #打印变量类型,以确定是否正确
job = input("job:")
message1 = '''----------information of %s----------
name:%s
age:%d #%d代表整型
job:%s
''' % (name,name,age,job)
print(message1)
name = input("name:")
age = input("age:")
job = input("job:")
message2 = '''----------information of {_name}----------
name:{_name}
age:{_age}
job:{_job}
'''.format(_name=name,_age=age,_job=job)
还有另外一种大括号格式化字符串方法:
message3 = '''----------information of {0}----------
name:{0}
age:{1}
job:{2}
'''.format(name,age,job)
print(message3)
当使用‘’‘%s’‘’时,后面接在用%(变量名)
当使用‘’‘{_name}’‘’时,后面接在用 .format(_name=name)
name = input("name:")
age = input("age:")
job = input("job:")
print('my name is {0}, age is {1},job is {2}'.format(name,age,job))
输入结果:
name:kang
age:30
job:it
my name is kang, age is 30,job is it
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。