【Python笔记】两种格式化输入的方法

版权声明:看不尽的尘埃版权所有,转载请注明出处 https://blog.csdn.net/weixin_42936566/article/details/87857166

1、%法

2、format法

#!/usr/bin/python
# -*- coding:utf-8 -*-
# wirter:En_dust

name = input("name:")
age = int(input("age:"))
info = input("info:")

value1 = '''
    ---------------------information---------------------
    name:{_name}
    age:{_age}
    info:{_info}
'''.format(_name = name,_age = age,_info = info)

value2 = '''
    ---------------------information---------------------
    name:%s
    age:%d
    info:%s
''' % (name,age,info)


print(value1)
print(value2)

猜你喜欢

转载自blog.csdn.net/weixin_42936566/article/details/87857166