Print Single and Multiple variable in Python
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:
- How to write an empty function in Python - pass statement?
- Operator Functions in Python | Set 2
- Time Functions in Python | Set-2 (Date Manipulations)
- Send mail from your Gmail account using Python
- Python – The new generation Language
- Increment and Decrement Operators in Python
- str() vs repr() in Python
- Swap two variables in one line in C/C++, Python, PHP and Java
- Generate all permutation of a set in Python
- Class or Static Variables in Python
- trunc() in Python
- Division Operators in Python
- Interesting facts about strings in Python | Set 1
- When to use yield instead of return in Python?
- How to split a string in C/C++, Python and Java?



