首页 > 解决方案 > Python - 如果变量在打印函数中,则换行,需要修复

问题描述

我在 Python 中打印有一个问题,我开始学习 Python,但是当我想在打印函数中打印变量时,看起来在一个变量之后它会在结果中添加换行符:

print(game_name + " | " + rating)

我正在制作一个游戏数据库,其中包含我自己对游戏的评分,但是如果它打印游戏并且评分就像一个空行 belpw 写了游戏名称和评分,我该如何删除那个空换行符?我对此很陌生,所以请不要吝啬...

标签: python

解决方案


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)

推荐阅读