I wish to understand the output of print((x,y)*5)
. I wish to know what actually is happening behind the scenes. (To me, it seems as if it turned into a list. Am I right?)
x = 'Thank'
y = 'You'
print(x+y)
print(x,y)
print((x+y)*5)
print((x,y)*5) #This one..
I am a beginner in Python and I'm asking a question for the first time ever. Please forgive me if this question seems naive. I tried Googling but it didn't help.
In Python 3, we get a print function, which we can also use in Python 2. The print statement with commas separating items, uses a space to separate them. A trailing comma will cause another space to be appended. No trailing comma will append a newline character to be appended to your printed item.
Print Statements with Commas (Python 2) The print statement with commas separating items, uses a space to separate them. A trailing comma will cause another space to be appended. No trailing comma will append a newline character to be appended to your printed item.
Different Styles Of Print Statements In Python Programming. 1 1)Numbered Indexes PROGRAM OUTPUT The two numbers are 10 and 20. 2 2)Named Indexes PROGRAM OUTPUT. 3 3)EMPTY PLACEHOLDER PROGRAM OUTPUT.
In Python 2, we had print statements. In Python 3, we get a print function, which we can also use in Python 2. The print statement with commas separating items, uses a space to separate them. A trailing comma will cause another space to be appended. No trailing comma will append a newline character to be appended to your printed item.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With