关闭。这个问题需要更多focused .它目前不接受答案。
想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post .
2年前关闭。
Improve this question
我想了解 print((x,y)*5)
的输出.我想知道幕后到底发生了什么。 (对我来说,它似乎变成了一个列表。我说得对吗?)
x = 'Thank'
y = 'You'
print(x+y)
print(x,y)
print((x+y)*5)
print((x,y)*5) #This one..
我是 Python 的初学者,这是我第一次提出问题。如果这个问题看起来很幼稚,请原谅我。我试过谷歌搜索,但没有帮助。
最佳答案
x = 'Thank'
y = 'You'
# concatenation of string x and y which is treated as a single element and then
# printed (Here, only a single argument is passed to the print function).
print(x+y)
# Output: ThankYou (Simple String concatenation)
# Here, two different arguments are passed to the print function.
print(x,y)
# Output python 2: ('Thank', 'You') (x and y are treated as tuple
# Output python 3: Thank You (x and y are comma seperated and hence,
# considered two different elements - the default 'sep=" "' is applied.)
# The concatenated result of (x + y) is printed 5 times.
print((x+y)*5)
# Output: ThankYouThankYouThankYouThankYouThankYou
# x and y are made elements of a tuple and the tuple is printed 5 times.
print((x,y)*5)
# Output: ('Thank', 'You', 'Thank', 'You', 'Thank', 'You', 'Thank', 'You', 'Thank', 'You')
关于python - python打印语句中逗号和加号有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54663742/