Consider below two Python code snippets in Python 2.x.
# Code 1 print 1# Output: 1 |
# Code 2 print(1) # Output: 1 |
There is no difference between code 1 and code 2 in case of single variable in Python 2.X, but in case of multiple variables, variable with brackets -() is treated as “tuple”.
For multiple variable:
- “print variable” prints the variables without any brackets ‘()’ and splitted by a space
- “print(variable)” prints the variables with brackets ‘()’ and splitted by a coma ‘,’ so it’s treated as a tuple.
Examples-
# Code 3 print 1, 2# Output: 1 2 |
# Code 4 print (1, 2) # Output: (1, 2) |
Note:
In Python 3.0, the print statement is changed to print() function. Below are equivalent codes in Python 3.0.
# Equivalent codes in Python 3.0 # (Produces same output) # Code 1: print(1) # Output: 1 # Code 2 : print((1)) # Output: 1 # Code 3: print(1, 2) # Output: 1 2 # Code 4: print((1, 2)) # Output: (1, 2) |
This article is contributed by Arpit Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Recommended Posts:
- Python | Convert a list of multiple integers into a single integer
- __name__ (A Special variable) in Python
- Python | Set 6 (Command Line and Variable Arguments)
- A single neuron neural network in Python
- Transpose a matrix in Single line in Python
- Multiplication of two Matrices in Single line using Numpy in Python
- Python code to move spaces to front of string in single traversal
- Python | Initializing multiple lists
- Returning Multiple Values in Python
- Rename multiple files using Python
- Remove multiple elements from a list in Python
- Python | Add similar value multiple times in list
- Python dictionary with keys having multiple inputs
- Python | Iterate over multiple lists simultaneously
- Taking multiple inputs from user in Python



