python - 一个字符串到上和下
问题描述
我正在尝试使用此代码使第一行在上,第二行在下,但我不知道如何在同一个字符串中使用两者。正如您在代码中看到的那样,我已经将它放在了上。所有的帮助将不胜感激!
example_string = "This is the first line\nand this is the second line "
new_string = example_string.splitlines()
print(example_string.upper())
解决方案
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())
推荐阅读
- java - 数组列表
与数组列表 ? - python - 如何在pytorch中动态索引张量?
- java - 有什么方法可以处理 API 调用返回的“数组响应”
- ajax - ajax 发布 API 403(禁止)
- html - Bootstrap 'align-content-around' 不起作用
- xml - 无法使用 XPath 将 XML 数据解析为 Java 对象
- sql - 将基表值与第二个表的值总和与 group by 进行比较
- laravel - laravel vanilo.io 中的反射异常
- python - pandas.to_sql 写入 redshift 失败并出现 NotSupportedError
- javascript - 变量赋值与直接传递给函数