• Register
0 votes
492 views

Problem :

When I try to use a print statement in Python, it gives me below error:
SyntaxError: Missing parentheses in call to 'print'
6 5 3
6,930 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

The error message suggests that you are attempting to use Python 3 to run a program that uses the Python 2 print statement:

In Python 3 you need to add parentheses around the value to be printed:

print("Hello, World!")

Further Readings:

https://github.com/BitMEX/easy-data-scripts/issues/1

9 7 4
38,600 points
0 votes

Solution:

This error message implies that you are trying to employ Python 3 to pursue an example or run a program that uses the Python 2 print statement:

The statement above does not perform in Python 3. In Python 3 you require to include parentheses around the value to be printed:

print("Hello, World!")

“SyntaxError: Missing parentheses in call to 'print'” is a new error message that was included in Python 3.4.2 primarily to help users that are attempting to pursue a Python 2 tutorial while running Python 3.

In Python 3, printing values altered from being a distinct statement to being an ordinary function call, hence it now requires parentheses:

>>> print("Hello, World!")
Hello, World!

In prior versions of Python 3, the interpreter only reports a generic syntax error, without giving any helpfl hints as to what might be going wrong:

>>> print "Hello, World!"
  File "<stdin>", line 1
    print "Hello, World!"
                        ^
SyntaxError: invalid syntax

As for why print became an ordinary function in Python 3, that didn't connect to the basic form of the statement, however rather to how you did more complicated things like printing multiple items to stderr with a trailing space rather than ending the line.

In Python 2:

>>> import sys
>>> print >> sys.stderr, 1, 2, 3,; print >> sys.stderr, 4, 5, 6
1 2 3 4 5 6

In Python 3:

>>> import sys
>>> print(1, 2, 3, file=sys.stderr, end=" "); print(4, 5, 6, file=sys.stderr)
1 2 3 4 5 6

Begining with the Python 3.6.3 release in September 2017, few error messages connected to the Python 2.x print syntax have been updated to recommend their Python 3.x counterparts:

>>> print "Hello!"
  File "<stdin>", line 1
    print "Hello!"
                 ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello!")?

Because the "Missing parentheses in call to print" instance is a compile time syntax error and therefore has access to the raw source code, it's able to add the full text on the rest of the line in the expressed replacement. But, it doesn't presently attempt to perform out the appropriate quotes to place around that expression (that's not impossible, only sufficiently complicated that it hasn't been done).

The TypeError moved for the right shift operator has also been customised:

>>> print >> sys.stderr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and '_io.TextIOWrapper'. Did you mean "print(<message>, file=<output_stream>)"?

Because this error is moved at the time the code runs, rather than when it is compiled, it doesn't have access to the raw source code, and therefore employes meta-variables (<message> and <output_stream>) in the revealed replacement expression instead of whatever the user really typed. Unlike the syntax error instance, it's straightforward to place quotes around the Python expression in the custom right shift error message.

10 6 4
31,120 points

Related questions

1 vote
1 answer 75 views
75 views
Problem: I am a newbee in programmingand I am doing a online course on python. To follow that course I wrote a code: def add(x , y): return x + y def del(x, y): return x - y choice = int(input("Please enter your Choice: ")) print 1.For addition print ... error like: File "calc.py", line 7 print 1.For addition ^ SyntaxError: Missing parentheses in call to 'print' What should I do now please help
asked Apr 4, 2020 LizzyM 6.1k points
0 votes
1 answer 39 views
39 views
I am new to pyhton programming . I was doing some coding practice. I wrote a code: def addition(a , b): return a + b def delete(a, b): return a - b choice = int(input("Please enter your Choice: ")) print 1.For addition print 2.For delete but it gives me some error like: File "main.py", line 7 print 1.For addition ^ SyntaxError waht is the problem with my code can anyone help?
asked Mar 15, 2020 LizzyM 6.1k points
0 votes
1 answer 125 views
125 views
Problem: I have freshly migrated my project from the old python2 to the new python3 and it has hundreds of the ForeignKey relations. I have very basic knowledge related to python. Using a solution to go line by line and add on_delete argument is not the possible. What ... it does not look like catching it somehow. Looking for a Python expert who can try to fix my above Python error very quickly.
asked Jul 15, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 851 views
851 views
Problem : I learning Python with the help of free online Python tutorial which wants me to write following Program: Create a temperature converter which will convert Fahrenheit values to Celsius and vice-versa using the following two formulas which relate the temperature f in Fahrenheit to ... ,sep ='') if inputString[-1] == 'F': farenheit = inputDigit print(celsiusConvert(farenheit),'C', sep='')
asked Nov 21, 2019 peterlaw 6.9k points
1 vote
2 answers 105 views
105 views
Problem : The program supposed to take in two names, and if they are the same length it should check if they are the same word. But i am getting below error in python python typeerror: not all arguments converted during string formatting
asked Oct 21, 2019 peterlaw 6.9k points
0 votes
1 answer 18 views
18 views
Task: Read an integer N . For all non-negative integers i<N , print i2. if __name__ == '__main__': n = int(input()) if (n<=0) and (n>=20): print("Exit") else: for(i=0,i<=n,i++): print(i*i) I am getting below error File "solution.py", line 6 for(i=0,i<=n,i++): ^ SyntaxError: invalid syntax Exit Status 255
asked Oct 25, 2020 psandprop 2.4k points
0 votes
1 answer 9 views
9 views
Problem: runtimewarning: divide by zero encountered in double_scalars
asked Feb 16 Ethan ross 1.8k points
0 votes
1 answer 570 views
570 views
Problem : Please find below my code for your reference. import os for root, dirs, files in os.walk('Path'):      for file in files:          if file.endswith('.c'):              with open(os.path.join(root, file)) as f:                     for line in f: ... already tried setting it with the open(os.path.join(root, file),'r',encoding='cp932') as f: but got the same above error
asked Jan 31, 2020 jwilliam 3.9k points
0 votes
1 answer 113 views
113 views
Problem : I am unable to understand what am I missing here: Sort my_short_names in reverse alphabetic order. The sample output from the given program as below : ['Tody', 'Samy', 'Joey', 'Jany', 'Anny'] Below is my code for your reference : my_short_names = ['Jany', 'Samy', 'Anny', 'Joey', 'Tody'] my_short_names.sort() print(my_short_names)
asked Jan 8, 2020 alecxe 7.5k points