python3中 format方法的一些问题
PHP中文网
PHP中文网 2017-04-18 10:26:10
0
4
561

_manny = int(input('请输入您的预算:')) #预算

_cargo = [['iphone', 5888], ['computer', 6400], ['desk', 800], ['pen', 40], ['smoke', 400]] # 商品清单

_quit = 'q' # 按q退出

_consume = 0 # 消费金额

print('以下是为您准备的商品列表,请按对应序号选择您需要的商品:')

for i in range(4):

print('序号{}','商品名称:{}','商品单价:{}'.format(i+1,_cargo[i][0], _cargo[i][1]))

初学 format方法学的不是很好。这里老是要不了自己想要的结果。请老司机带带。。。

PHP中文网
PHP中文网

认证0级讲师

répondre à tous(4)
阿神
>>> print('序号{},商品名称:{},商品单价:{}'.format(1,2, 3))
序号1,商品名称:2,商品单价:3
大家讲道理
>>> for i in range(4):
        print('序号{}'.format(i+1),'商品名称:{}'.format(_cargo[i][0]),'商品单价:{}'.format( _cargo[i][1]))

    
序号1 商品名称:iphone 商品单价:5888
序号2 商品名称:computer 商品单价:6400
序号3 商品名称:desk 商品单价:800
序号4 商品名称:pen 商品单价:40


你要的是这样的效果吗?
小葫芦
print('序号{0:}','商品名称:{1:}','商品单价:{2:}'.format(i+1,_cargo[i][0], _cargo[i][1]))
左手右手慢动作

pour moi dans la plage(4) :

print('序号{0} 商品名称:{1} 商品单价:{2}'.format(i+1,_cargo[i][0], _cargo[i][1]))
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!