Rumah > Soal Jawab > teks badan
# -*- coding:utf-8 -*-
#字典使用人名作为键,每个人用另一个字典表示
people = {
'mary' : {
'phone' : '123456',
'addr' : 'xingfudadao123456'
},
'alice' : {
'phone' : '890123',
'addr' : 'xingfudadao890123'
},
'cecil' : {
'phone' : '456789',
'addr' : 'xingfudadao456789'
}
}
labels = {
'phone' : 'phone_number',
'addr' : 'address'
}
name = input('Name:')
request = input('Phone number(p) or address(a)?')
if request == 'p':key = 'phone'
if request == 'a':key ='addr'
if name in people:print("%s's %s is %s." % \)
(name,labels[key],people[name][key])
#请问最后两句代码:if name in people:print("%s's %s is %s." % \)
(name,labels[key],people[name][key])
怎么解释呢?运行还报错了
阿神2017-04-18 10:15:21
Ini adalah output berformat Anda boleh memahaminya apabila ditulis seperti ini.
if name in people:
print("%s's %s is %s." % \
(name,labels[key],people[name][key]))
Jika anda mempunyai sebarang keraguan, tulis ini.
if name in people:
print("%s's %s is %s." % (name, labels[key], people[name][key]))
PHPz2017-04-18 10:15:21
if name in people:
print("{0}'s {1} is {2}.".format(name, labels[key], people[name][key]))
巴扎黑2017-04-18 10:15:21
pyformat
if name in people:print("%s's %s is %s." % \
(name,labels[key],people[name][key]))
if name in people:
print("%s's %s is %s." % (name,labels[key],people[name][key]))
#print("{}'s {} is {}.".format(name,labels[key],people[name][key]))