如何在for循环中打印字符串而没有一行空格 [英] How to print strings in a for loop without space in one line

查看:72
本文介绍了如何在for循环中打印字符串而没有一行空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在for循环中的一行中打印一些字符串而彼此之间没有空格.

I am wondering how can I print some strings in a for loop in one line without space between each other.

我知道在一行中没有空间的情况下串联字符串,但是在for循环之外:

I know concatenating strings without space in one line, but outside of a for loop:

>>> print('hi'+'hi'+'hi')
hihihi

但是,我不知道如何在for循环中做到这一点.

However, I have no idea how to do that in a for loop.

推荐答案

s = ""
for i in range(3):
    s += 'Hi'
print(s)

这篇关于如何在for循环中打印字符串而没有一行空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆