我无法在python上的输出上添加空格

2024-05-13 15:05:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Farhan Sadik和Snigdho上留个空间

enter image description here

我在间隔NameName2Welcome上尝试了很多次,但是没有结果


Tags: name间隔空间welcomename2farhansnigdhosadik
3条回答

您只需添加一个空格即可解决此问题:

Name + " " + Name2 + " " + third_variable

实际上,你把字符串连在一起,它们之间没有空格

你可以做:

print("Hi", name1, name2, welcome)

或:

print("Hi " + name1 + " " + name2 + " " + welcome)

print(Name + " " + Name2 + " " + "WELCOME")

输出:

Value of Name value of name2 WELCOME

If comma(,) is used in the place of " " it will also give the same output (as above)

上面的代码打印名称的值和空格(“”),然后再打印名称2和空格(“”)以及字符串“欢迎”

In the same way if you use \n in the space of " " you will get the output of the string or variable next to the \n in a new line. For example:

print(Name + "\n" + Name2 + "\n" + "WELCOME")    

输出:

Value of Name
Value of Name2
WELCOME

In the same way if \t is used in the place of \n it will print the variable or string next to it after a tab space, like:

输出:

Value of Name      Value of Name2       WELCOME

相关问题 更多 >