python 格式化输出-Python基本语法

阅读: 409 | 文章分类: Python | Tag: Python  

# Python格式化输出 ## 方式一 ``` name=input('name:') age=input('Age:') job=input('Job:') salary=input('Salary:') info=''' -------- info of %s ---------- Name:%s Age:%s Job:%s Salary:%s '''%(username,username,age,job,salary) print(info) ``` ## 方式二 ``` name=input('name:') age=input('Age:') job=input('Job:') salary=input('Salary:') info2=''' -------- info of {_name} ---------- Name:{_name} Age:{_age} Job:{_job} Salary:{_salary} ''' .format(_name=name, _age=age, _job=job, _salary=salary) print(info2) ``` ## 方式三 ``` name=input('name:') age=input('Age:') job=input('Job:') salary=input('Salary:') info3=''' -------- info of {0} ---------- Name:{0} Age:{1} Job:{2} Salary:{3} '''.format(name,age,job,salary) print(info3) ``` ## 方式四 ``` name=input('name:') age=input('Age:') job=input('Job:') salary=input('Salary:') info4=''' -------- info of '''+ name +''' ---------- Name:'''+ name +''' Age:'''+ age +''' Job:'''+ job +''' Salary:'''+ salary +''' ''' print(info4) ```