#encoding:utf-8
#有多组输入数据,但组数不确定
while True:
try:
a, b = map(int, input().split(' ')) #以空格隔开
print(a + b) #map(int, list)把每个list的元素转为int型
except EOFError: #捕捉异常
break
#先输入一个整数,告诉我们接下来有多少组数据,然后在输入每组数据的具体值。,
n = int(input())
for temp in range(n): #range(5)等价于list[0, 1, 2, 3, 4]
a, b = map(int, input().split(' '))
print(a + b)
# 有多组输入数据,没有具体的告诉有多少组,但是却知道遇见什么结束
while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break
else:
print(a + b)
#有多组输入数据,对于每组输入数据的第一个数代表该组数据接下来要输入数据量
while True:
try:
lst1 = list(map(int, input().split()))
n, lst = lst1[0], lst1[1:]
sum = 0 #对后面n个数据求和
for i in range(n):
sum += lst[i]
print(sum)
except EOFError:
break
#把输入的字符串分成单个字符处理
while True:
lst = list(input())
print(lst)
#print输出不换行
print ("Hello ", end='') #输出为: Hello World!
print ("World", end='')
print("!")
#打印字符串
print("His name is%s"%("zhangsan")) #输出为: His name is zhangsan
#打印整数
print("He is%dyears old"%(25)) #输出为: He is 25 years old
#打印浮点数
print("His weight is%f"%(155.5)) #输出为: His weight is 155.500000
#打印浮点数并指定保留小数点位数
print("His weight is%.2f"%(155.5)) #输出为: His weight is 155.50
#指定占位符宽度
print("Name:%10sAge:%3dHeight:%8.2f"%("zhangsan", 25, 155.5))
#输出为: Name: zhangsan Age: 25 Height: 155.50
#指定占位符宽度(左对齐)
print("Name:%-10sAge:%-3dHeight:%-8.2f"%("zhangsan", 25, 155.5))
#输出为: Name:zhangsan Age:25 Height:155.50
#用0当占位符
print("Name:%-10sAge:%03dHeight:%08.2f"%("zhangsan", 25, 155.5))
#输出为: Name:zhangsan Age:025 Height:00155.50
#输出16进制,十进制,8进制整数
n = 100
print("hex =%x, dec =%d, oct =%o"%(n, n, n)) #输出为: hex = 64, dec = 100, oct = 144
#指数输出
print("%.3e" %2016) #输出2.016e+03,也可以写大E
#输出列表
lst = [1,2,3,4,'python']
print (lst) #输出为: [1, 2, 3, 4, 'python']
#format的使用:通过{}和:来代替传统%方式
#使用位置参数
list = ['zhangsan', 20]
print("my name is {}, age is {}".format('zhangsan', 20)) #输出为: my name is zhangsan, age is 20
print("my name is {1}, age is {0}".format(20, 'zhangsan')) #输出为: my name is zhangsan, age is 20
print("my name is {1}, age is {0} and I am {1}".format(20,'zhangsan'))
#输出为: my name is zhangsan, age is 20 and I am zhangsan
print("my name is {}, age is {}".format(*list)) #输出为: my name is zhangsan, age is 20
print("{a[0]}{a[1]}{a[2]}".format(a=["spkk",".","cn"])) #输出spkk.cn
#使用关键字参数(使用字典)
student = {'name': 'zhangsan', 'age': 20}
print("my name is {name}, age is {age}".format(name = 'zhangsan', age = 20))
#输出为: my name is zhangsan, age is 20
print("my name is {name}, age is {age}".format(**student))
#输出为: my name is zhangsan, age is 20
#填充和格式化
print("{:,}".format(123456))#输出1234,56
print("{a:x^8}".format(a="8"))#输出xxx8xxxx,填充x