python - Python - 如果变量在打印函数中,则换行,需要修复
问题描述
我在 Python 中打印有一个问题,我开始学习 Python,但是当我想在打印函数中打印变量时,看起来在一个变量之后它会在结果中添加换行符:
print(game_name + " | " + rating)
我正在制作一个游戏数据库,其中包含我自己对游戏的评分,但是如果它打印游戏并且评分就像一个空行 belpw 写了游戏名称和评分,我该如何删除那个空换行符?我对此很陌生,所以请不要吝啬...
解决方案
Welcome to Stack Overflow! The most likely culprit is that there is a newline at the end of the game_name
variable. The easy fix for this is to strip it off like this:
print(game_name.strip() + " | " + rating)
推荐阅读
- c++ - QMetaObject::indexOfMethod() 寻找槽失败
- c# - 无法更改 IBM MQ XMS.NET 客户端重新连接超时
- import - 无法将字体导入 mjml
- javascript - 在页面加载期间无法更改表单子元素的边框颜色
- identityserver4 - UnauthorizedAccessException:对路径 'c:\windows\system32\inetsrv\tempkey.rsa' 的访问被拒绝。”
- c - C语言:在另一个文件中的main.c文件中使用枚举变量和类型定义的麻烦
- maven - 无需从存储库获取依赖项即可自动部署 EAR 项目
- css - Flexbox - 行内相同高度的列
- local-variables - Exasol 中的变量声明
- python - 在 Pandas 中为行中的空单元格附加单元格值