欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python的格式化输出

程序员文章站 2024-03-15 15:24:24
...
chapter1> ./info.py
my name is:"James"
my job is:"IT"
my salary is:"30000"

============ My personal info is ===========
my name is James
my job is IT
my salary is 30000
[Linux]                                                                                                    
[tcsh] chapter1> cat info.py
#!/usr/bin/env python
#_*_coding:utf-8_*_

myName = input("my name is:")
myJob = input("my job is:")
mySalary = input("my salary is:")

myinfo = '''
============ My personal info is ===========
my name is '''+ myName + '''
my job is ''' + myJob + '''
my salary is ''' + mySalary

print(myinfo)
[Linux]                                                                                                     
[tcsh] chapter1>
myname = input("myname:")
myJob = input("myjob:")
mySalary = input("mySalary:")
'''
info = "What's your name?," +"I asked."
+"He said" + "My name is" + myname
+"and my job is " + myJob
+"my salary is " + mySalary
'''
myInfo = '''======== MY PERSONAL INFO ==========
\tmy name is %s
\tmy job is %s
\tmy salary is %s
'''%(myname,myJob,mySalary)

print(myInfo)

output as below shows

================= RESTART: C:/Users/hanwuwex/Desktop/test.py =================
myname:james
myjob:it
mySalary:500000
======== MY PERSONAL INFO ==========
	my name is james
	my job is it
	my salary is 500000

>>> 
相关标签: python