首页 > 解决方案 > 如何在 Python 中使用 .upper 函数格式化大写的完整句子?

问题描述

我想从我的代码中生成一行,以便它以大写形式显示。

这是我到目前为止的代码:


a= 98
b= 88
c= 78
d = """ I want {} kilos of gram
and it want {} kilos of magi also i want
{} of ginger """

print(d.format(a,b,c) and (d.upper()))

输出应显示为:

"""我想要 {98} 公斤的克,它想要 {88} 公斤的魔法师,我还想要 {78} 的生姜 """

标签: pythonstring

解决方案


a= 98
b= 88
c= 78
d = """ I want {} kilos of gram
and it want {} kilos of magi also i want
{} of ginger """

print(d.format(a,b,c).upper()) # modification is here
Out[1]:
 I WANT 98 KILOS OF GRAM
AND IT WANT 88 KILOS OF MAGI ALSO I WANT
78 OF GINGER

推荐阅读