End 在循环中的 print() 函数中不起作用

发布于 2025-01-12 23:23:32 字数 191 浏览 2 评论 0原文

我正在尝试执行以下代码,但它没有给我任何输出。当我从打印中删除结尾时,它会给我输出,但集合中的每个元素都在新行上打印。为了摆脱这个问题,我在打印中使用 end 但它不起作用。请帮忙!

myset={'Haider','Wali','Aamir'}
for x in myset:
    print(x,end='')

I am trying the following code to execute which is giving me nothing in output. And when I remove end from print then it gives me the output but every element of the set is printing on new line. To get rid of this I am using end in print but its not working. PLEASE HELP!!

myset={'Haider','Wali','Aamir'}
for x in myset:
    print(x,end='')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

滥情哥ㄟ 2025-01-19 23:23:32

由于代码显示不清晰,并且评论中无法附加图像,我写下这个答案,如下:

myset={'Haider', 'Wali', 'Aamir'}
for x in myset:
    print(x, end='')
#AamirHaiderWali -> output

print()

for x in myset:
    print(x, end=' ') # one space inside the single quotation marks
#Aamir Haider Wali -> output on single line as what you desired.

以下是代码结果的图像。

输入图片此处描述

As a code is not clearly shown and an image cannot be attached on a comment, I write this answer, as follows:

myset={'Haider', 'Wali', 'Aamir'}
for x in myset:
    print(x, end='')
#AamirHaiderWali -> output

print()

for x in myset:
    print(x, end=' ') # one space inside the single quotation marks
#Aamir Haider Wali -> output on single line as what you desired.

Following is an image of the result of the code.

enter image description here

安静 2025-01-19 23:23:32

我认为您在结束参数中缺少一个空格。尝试 print(x, end=' ')

I think you are missing a space in the end parameter. Try print(x, end=' ')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文