Python中的连接问题 [英] Concatenation question in Python

查看:63
本文介绍了Python中的连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有其他方法可以使用'for'或'while'条件来编码?



who = ['Gary','Kevin'] < br $> b $ b how_many = [12,34]



打印({}想要{}苹果。而{}想要{}橘子。格式(谁[0],how_many [0],谁[1],how_many [1]))

- >加里想要12个苹果。凯文想要34个橘子。



我尝试过:



who = ['Gary','Kevin']

how_many = [12,34]



打印({}想要{}苹果。{}想要{}橘子。。格式(谁[0],how_many [0],谁[1],how_many [1]))

- >加里想要12苹果。凯文想要34个橘子。

解决方案

尝试字典: 5。数据结构 - Python 3.4.7rc1文档 [ ^ ]。

Is there any other way to code this by using 'for' or 'while' conditional?

who = ['Gary','Kevin']
how_many=[12, 34]

print("{} wants {} apples. And {} wants {}oranges.". format(who[0],how_many[0],who[1],how_many[1]))
-->Gary wants 12 apples. And Kevin wants 34 oranges.

What I have tried:

who = ['Gary','Kevin']
how_many=[12, 34]

print("{} wants {} apples. And {} wants {}oranges.". format(who[0],how_many[0],who[1],how_many[1]))
-->Gary wants 12 apples. And Kevin wants 34 oranges.

解决方案

Try a Dictionary: 5. Data Structures — Python 3.4.7rc1 documentation[^].


这篇关于Python中的连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆