cari

Rumah  >  Soal Jawab  >  teks badan

python - print("%s's %s is %s." % \) 有具体代码,请问这种怎么解释?

# -*- 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])
    怎么解释呢?运行还报错了
天蓬老师天蓬老师2802 hari yang lalu2720

membalas semua(3)saya akan balas

  • 阿神

    阿神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]))

    balas
    0
  • PHPz

    PHPz2017-04-18 10:15:21

    if name in people:
        print("{0}'s {1} is {2}.".format(name, labels[key], people[name][key]))

    balas
    0
  • 巴扎黑

    巴扎黑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]))

    balas
    0
  • Batalbalas