在输入字符串的开头添加了一个空间
我正在尝试通过获取用户输入来打印一条线。 但是在打印用户输入之前有一个空白:
代码:
UserInput = input('Enter a string: ')
print("\nEntered string is:\n", UserInput)
输出:
Enter a string: I need this, but not this
Entered string is:
I need this, but not this
理想情况下,输出应该是: 输入一个字符串:我需要这个,但不要这个,
Entered string is:
I need this, but not this
请有人让我知道吗?
I am trying to print a line by taking the user input.
But there is an empty space before the user input is printed:
Code:
UserInput = input('Enter a string: ')
print("\nEntered string is:\n", UserInput)
Output:
Enter a string: I need this, but not this
Entered string is:
I need this, but not this
Ideally the output should have been:
Enter a string: I need this, but not this
Entered string is:
I need this, but not this
Please can someone let me know??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
逗号在用户输入字符串之前会导致额外的空间。用
+
符号替换打印语句中的逗号。输出:
The comma is causing an extra space before the user input string. Replace the comma in the print statement with
+
sign.Output: