In Python 2.x print
is actually a special statement and not a function*.
This is also why it can’t be used like: lambda x: print x
Note that (expr)
does not create a Tuple (it results in expr
), but ,
does. This likely results in the confusion between print (x)
and print (x, y)
in Python 2.7
(1) # 1 -- no tuple Mister! (1,) # (1,) (1,2) # (1, 2) 1,2 # 1 2 -- no tuple and no parenthesis :) [See below for print caveat.]
However, since print
is a special syntax statement/grammar construct in Python 2.x then, without the parenthesis, it treats the ,
‘s in a special manner – and does not create a Tuple. This special treatment of the print
statement enables it to act differently if there is a trailing ,
or not.
Happy coding.
*This print
behavior in Python 2 can be changed to that of Python 3:
from __future__ import print_function
Related Posts:
- Print multiple arguments in Python
- Python Variable Declaration
- working of \n in python [duplicate]
- Pip freeze vs. pip list
- print variable and a string in python
- WinError 2 The system cannot find the file specified (Python)
- Could not find a version that satisfies the requirement tensorflow
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- pip or pip3 to install packages for Python 3?
- How to print to stderr in Python?
- How to print to stderr in Python?
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- multiple prints on the same line in Python
- Change figure size and figure format in matplotlib
- How can I flush the output of the print function?
- print variable and a string in python
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Type error Unhashable type:set
- TypeError: ‘_io.TextIOWrapper’ object is not subscriptable
- How to read the last line of a file in Python?
- Python 3 print without parenthesis
- What is the meaning of “int(a[::-1])” in Python?
- dump() missing 1 required positional argument: ‘fp’ in python json
- Does python have header files like C/C++?
- In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:
- SyntaxError: unexpected EOF while parsing
- How to use filter, map, and reduce in Python 3
- Use Gif Logo For Loading Screen In Kivy
- Praw & Discord.py: The bot keep sending the same meme. I want the bot to send different meme whenever it is asked
- How can I make a time delay in Python? [duplicate]
- Python – TypeError: ‘int’ object is not iterable
- TypeError: ‘int’ object is not subscriptable
- Understanding the main method of python [duplicate]
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- How to open a file using the open with statement
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- Microsoft Visual C++ 14.0 is required (Unable to find vcvarsall.bat)
- How to install pip with Python 3?
- What is the difference between rw+ and r+
- Convert bytes to a string
- How can I represent an ‘Enum’ in Python?
- Python – TypeError: ‘int’ object is not iterable
- Import Error: No module named numpy
- Python3 – ModuleNotFoundError: No module named ‘numpy’
- What is the purpose of the return statement?
- Relative imports – ModuleNotFoundError: No module named x
- Python: ‘ModuleNotFoundError’ when trying to import module from imported package
- Relative imports – ModuleNotFoundError: No module named x
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- How to uninstall a package installed with pip install –user
- What is the result of % in Python?
- How do I upgrade the Python installation in Windows 10?
- Reading an Excel file in python using pandas
- Error: ‘int’ object is not subscriptable – Python
- not all arguments converted during string formatting.. NO % variables
- How do I use raw_input in Python 3
- How do I compare two strings in python?
- Relative imports in Python 3
- Relative imports in Python 3
- TypeError: ‘int’ object is not callable
- TypeError: ‘int’ object is not callable
- TypeError: ‘int’ object is not callable
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- What does the list() function do in Python?
- TypeError: not all arguments converted during string formatting python
- PermissionError: [Errno 13] Permission denied
- Cannot find module cv2 when using OpenCV
- What is setup.py?
- How is Anaconda related to Python?
- PermissionError: [Errno 13] in Python
- Cannot find module cv2 when using OpenCV
- How to best print output to command window during a loop in Matlab?
- Python ‘If not’ syntax [duplicate]
- FileNotFoundError: [WinError 2] The system cannot find the file specified:
- RuntimeWarning: invalid value encountered in divide
- Converting dictionary to JSON
- Invalid character in identifier
- Should I put #! (shebang) in Python scripts, and what form should it take?
- Should I put #! (shebang) in Python scripts, and what form should it take?
- Using Python 3 in virtualenv
- Relative imports in Python 3
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- How to remove EOFError: EOF when reading a line?
- IndexError: tuple index out of range —– Python
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- hashlib.md5() TypeError: Unicode-objects must be encoded before hashing
- TypeError: cannot unpack non-iterable NoneType object
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Is there a ‘foreach’ function in Python 3?
- Python inline if statement
- How to install python3 version of package via pip on Ubuntu?
- Updating a dictionary in python
- TypeError: cannot perform reduce with flexible type
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Convert bytes to a string
- How to copy a dictionary and only edit the copy
- How to print like printf in Python3?