python-用户输入,格式化输出
Posted 影子
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-用户输入,格式化输出相关的知识,希望对你有一定的参考价值。
# -*- coding:utf-8 -*-
# Author:DliYao
usernam = input("username: ")
password = input("password: ")
print(usernam,password)
#input 用户输入
#input为交互式用户输入
name = input("name: ")
age = input("age: ")
job = input("job: ")
salry = input("salry: ")
# %s=%string
info = \'\'\'
---- info of %s ----
Name:%s
Age:%s
Job:%s
salry:%s
\'\'\'%(name,name,age,job,salry)
print(info)
运行结果
#%d 数字类型
name = input("name: ")
age = int(input("age: "))
job = input("job: ")
salry = input("salry: ")
info2 = \'\'\'
---- info of %s ----
Name:%s
Age:%d
Job:%s
salry:%s
\'\'\'%(name,name,age,job,salry)
print(info2)
运行结果
name = input("name: ")
age = input("age: ")
job = input("job: ")
salry = input("salry: ")
info3 = """
---- info of {_name} ----
Name:{_name}
Age:{_age}
Job:{_job}
salry:{_salry}
""".format(_name=name,
_age=age,
_job=job,
_salry=salry)
print(info3)
运行结果
name = input("name: ")
age = input("age: ")
job = input("job: ")
salary = input("salary: ")
info4 = """
---- info of {0} ----
Name: {0}
Age: {1}
Job: {2}
Salary: {3}
""".format(name,age,job,salary)
print(info4)
运行结果
以上是关于python-用户输入,格式化输出的主要内容,如果未能解决你的问题,请参考以下文章