'End of statement expected' in pycharm [duplicate] - python

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 4 years ago.
Why am I getting this error (see linting) saying 'End of statement expected' in pycharm?
I am very new to python.

Try print with parenthesis in Python3 i.e. print(x) instead of print x

Related

Python2 And Python3 [duplicate]

This question already has answers here:
"print" throws an invalid syntax error in Python 3
(4 answers)
Closed 2 years ago.
This is for Python 2:
import re
print sum([int(i) for i in re.findall('[0-9]+',open(raw_input('What is the file you want to analyze?\n'),'r').read())])
But why do I get a syntax error with Python 3?
Python3
import re
print sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())])
That is because in Python3 you should use brackets around the argument for the print function.
print()
so your code will work as soon as you write
print(sum([int(i) for i in re.findall('[0-9]+',open(input('What is the file you want to analyze?\n')).read())]))

What is meaning of '#' operator? [duplicate]

This question already has answers here:
What is the '#=' symbol for in Python?
(3 answers)
What does the "at" (#) symbol do in Python?
(14 answers)
Closed 3 years ago.
I have come across this code and I have seen this unusual operation:
return Xtrain # eigenvectors[:2]
Does anyone know what it does?
Python documentation says:
Matrix Multiplication
Operator
a # b
Function
matmul(a, b)

How to call various strings without using %s? [duplicate]

This question already has answers here:
Type Error: Format Requires Mapping
(2 answers)
Closed 3 years ago.
text1="Python"
text2="with me"
print("Study %(language)s" %{'language':text1})
This works. But I am wondering whether it is using dictionary to call string?
print("Study %(language)s %(with whom)" %({'language':text1},{'with whom':text2}))
But it doesn't work. How can I fix it?
The error says 'format requires a mapping'
It would have worked, if you noticed that:
you've forgotten to put an s after %(with whom) --> %(with whom)s,
and instead of this %({'language':text1},{'with whom':text2}) --> %{'language':text1,'with whom':text2}
so the line would be like this:
print("Study %(language)s %(with whom)s" %{'language':text1,'with whom':text2})

Is it possible to create a statement in python? [duplicate]

This question already has answers here:
Can you add new statements to Python's syntax?
(13 answers)
Add new statements to Python without customizing the compiler
(2 answers)
Closed 4 years ago.
Can I create a statement in python 2.7?
Something similar to the print statement, that it's like a function, but gets the parameters without parenthesis.

How to run python in windows 7 [duplicate]

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 7 years ago.
i am new to python. i am try to run my first hello world program but i got an error msg.
please find below the screen shot
Error Msg look like this:
>>> print "hello"
File "" line1
print "hello"
^
SyntaxError: Missing parentheses in call to 'print'
You are using Python 3, In this version print is not a keyword it is a function.
Try this :
print("hello")
See changes in Python3 from Python 2

Categories