+ 8
Print in Python
#why do both these give the same output print("the CMBR\n\n []") print(("the CMBR\n\n []"))
23 Réponses
+ 5
Python executes the inner parenthesis first,then the outer
+ 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.
+ 6
The print() function prints the specified message to the screen, or other standard output device.
+ 4
Sanjay Kamath
print()
print ('abc')
Both are valid because both are function with and without argument.
+ 3
You want to print parenthesis with data
use this,
print("the CMBR\n\n []")
print("(the CMBR\n\n [])")
+ 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
+ 3
Why does python allow you to add parentheses, in print, without even an apostrophe..?
+ 2
Because both are same
+ 2
Thanks! how does this sound ? print(Mr,(Mr,(Mr…. Sounds like Eddie Murphy meets Sylvester Stallone..
+ 2
Rain would you feed a vegan pepperoni, when even onions are considered anions
+ 1
They are same
+ 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.
+ 1
Python always executes the inner parenthesis first and then, the outer.
+ 1
A͢J print(()) is allowed. This is redundant IMHO
+ 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.
+ 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.
+ 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.
+ 1
Rain
0
Change the sentence in anyone of them
0
You will find that