Print in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Print in Python

#why do both these give the same output print("the CMBR\n\n []") print(("the CMBR\n\n []"))

10th Apr 2021, 4:06 AM
Sanjay Kamath
Sanjay Kamath - avatar
23 Answers
+ 5
Python executes the inner parenthesis first,then the outer
21st Apr 2021, 5:55 AM
Alaa Aldeen Shammr
Alaa Aldeen Shammr - avatar
+ 9
Sanjay Kamath Paranthesis () just tell you that you are using method. Doens't matter how much time you write it. It will always give same output.
10th Apr 2021, 4:22 AM
A͢J
A͢J - avatar
+ 6
The print() function prints the specified message to the screen, or other standard output device.
21st Nov 2021, 3:47 AM
Vaibhav
Vaibhav - avatar
+ 4
Sanjay Kamath print() print ('abc') Both are valid because both are function with and without argument.
14th Jan 2023, 3:35 PM
A͢J
A͢J - avatar
+ 3
You want to print parenthesis with data use this, print("the CMBR\n\n []") print("(the CMBR\n\n [])")
8th Oct 2021, 2:17 AM
N. Vimukthi Dilshan Fernando
+ 3
You can use this 👇 print("(the CMBR\n\n [])") to print parenthesis in the output... Since python executes parenthesis starting from inner to the outer ones, it won't matter how many parenthesis have been used
11th Nov 2021, 3:39 PM
Saswat Samal
+ 2
Because both are same
10th Apr 2021, 4:10 AM
Codemurai
Codemurai - avatar
+ 2
Thanks! how does this sound ? print(Mr,(Mr,(Mr…. Sounds like Eddie Murphy meets Sylvester Stallone..
4th Sep 2022, 3:13 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Why does python allow you to add parentheses, in print, without even an apostrophe..?
14th Jan 2023, 3:24 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Rain would you feed a vegan pepperoni, when even onions are considered anions
8th Jan 2024, 6:05 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
They are same
26th Apr 2022, 7:46 AM
Ifeanyi
+ 1
the "print" function requires paranthesis surrounding anything you want to display in the console. for example: print("Hello World!") OR print((Hello World!")) paranthesis can be used infinite times after the print statement but the output will always remain same.
4th Sep 2022, 1:32 PM
Altair Enigma
Altair Enigma - avatar
+ 1
Python always executes the inner parenthesis first and then, the outer.
14th Jan 2023, 10:40 AM
NIKHIL KUMAR SINHA
NIKHIL KUMAR SINHA - avatar
+ 1
A͢J print(()) is allowed. This is redundant IMHO
14th Jan 2023, 3:39 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 1
print(3*(3**2)-1) # Operate inner ()first print('first 3**2=9') print('second 3*9=27') print('third 27-1=26') #In Python, the double asterisk operator (**) represents exponentiation. It is used to raise a number to a certain power. For example, if you have the expression `2 ** 3`, it means 2 raised to the power of 3, which is equal to 8.
23rd Jun 2023, 9:31 AM
Chen Fu
Chen Fu - avatar
+ 1
In Python, using parentheses around a string in a `print` statement doesn't change the output. Both of the provided `print` statements will produce the same output. The parentheses are not necessary when passing a single argument to the `print` function. You can use either version based on your preference: ```python print("the CMBR\n\n []") ``` or ```python print(("the CMBR\n\n []")) ``` Both will result in the output: ``` the CMBR [] ``` The parentheses don't alter the behavior in this context; they are optional when printing a single item.
8th Jan 2024, 2:31 AM
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫
𝐀𝐲𝐞𝐬𝐡𝐚 𝐍𝐨𝐨𝐫 - avatar
+ 1
Sanjay Kamath , Python allows redundant parentheses anywhere. Redundant parentheses are parentheses that don't change the meaning of what they contain. Redundant parentheses are usually used in two ways to enhance readability. First, to visually reinforce existing operator precedence. # These statements are equivalent. a = b * c + d * e a = (b * c) + (d * e) a = b*c + d*e a = (b*c) + (d*e) Second, to spread long statements across visual lines. (Line continuation is implicit inside parentheses (), brackets [], and braces {}, so it is unnecessary to put \ at the end of each visual line.) # These statements are equivalent. montly_profit_or_loss = salary + tips + interest_earned - food - gas - rent - electricity - water - tax montly_profit_or_loss = ( salary + tips + interest_earned - food - gas - rent - electricity - water - tax ) Your code, print(("the CMBR\n\n []")) employs redundant parentheses without visual benefit.
8th Jan 2024, 6:53 AM
Rain
Rain - avatar
+ 1
Rain
8th Jan 2024, 6:03 PM
Sanjay Kamath
Sanjay Kamath - avatar
0
Change the sentence in anyone of them
10th Apr 2021, 4:10 AM
Codemurai
Codemurai - avatar
0
You will find that
10th Apr 2021, 4:11 AM
Codemurai
Codemurai - avatar