码迷,mamicode.com
首页 > 编程语言 > 详细

python 变量定义和打印输出实例

时间:2018-04-24 20:28:26      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:拼接   实例   pytho   type   打印   name   python   inf   str   

1、基础参数定义实例
print("hello world")

name = "PaoChe Ge"

name2 = name

duohang = ‘‘‘
print("My name is",name)

name = "Mr Li"

print(name2,"and",name)
‘‘‘

print(duohang) #打印duohang 多行!

username = input("username:")
password = input("password:")
print(username,password) #打印多个参数

2、打印输出:
name = input("name:")
age = int(input("age:") )
print(type(age) , type( str(age) ))
job = input("job:")
salary = input("salary:")

#不建议这种拼接方式,效率低下
info = ‘‘‘
---------------info of ----------
Name: ‘‘‘ + name + ‘‘‘
Age: ‘‘‘ + age + ‘‘‘
Job:‘‘‘+ job + ‘‘‘
Souru:‘‘‘+ souru +‘‘‘
‘‘‘


info1 =‘‘‘
---------------info of %s ----------
ame:%s
Age:%d
Job:%s
Salary:%s
‘‘‘ % (name,name,age,job,salary)


info2 = ‘‘‘ #建议这种方式
---------------info of {_name} ----------
Aame:{_name}
Age:{_age}
Job:{_job}
Salary:{_salary}
‘‘‘.format(_name=name,
_age=age,
_job=job,
_salary=salary)

info3 = ‘‘‘
---------------info of {0} ----------
Aame:{0}
Age:{1}
Job:{2}
Salary:{3}
‘‘‘.format(name,age,job,salary)
#print(info1)
print(info3)


python 变量定义和打印输出实例

标签:拼接   实例   pytho   type   打印   name   python   inf   str   

原文地址:https://www.cnblogs.com/wzsx/p/8932974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!