首页 > 解决方案 > 一个字符串到上和下

问题描述

我正在尝试使用此代码使第一行在上,第二行在下,但我不知道如何在同一个字符串中使用两者。正如您在代码中看到的那样,我已经将它放在了上。所有的帮助将不胜感激!

example_string = "This is the first line\nand this is the second line "
new_string = example_string.splitlines()
print(example_string.upper())

标签: pythonstring

解决方案


example_string = "This is the first line\nand this is the second line "
new_string = example_string.splitlines()
print(new_string[0].upper(), new_string[1].lower())

推荐阅读