Error in python 2.7 [duplicate] - python

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 5 years ago.
print "Hello %s !!!" %("Pruthvish")
^
SyntaxError: invalid syntax
When I run this in python IDLE it prints the output, but when I run this program through windows powershell it gives me syntax error. Why does this happen?

Put Brackets for print statement
print ("Hello %s !!!" %("Pruthvish"));

Related

How to print hello world in python? [duplicate]

This question already has answers here:
What does "SyntaxError: Missing parentheses in call to 'print'" mean in Python?
(11 answers)
Closed 2 years ago.
I tried running a python script:
print "Hello, World!"
but I get this error.
File "hello.py", line 1 print "Hello, World!" ^ SyntaxError: invalid syntax
What is going on?
The code you are writing is Python 2.x code, but your environment seems like Python 3.0.
here is code for python 3.x
print("Hello World")
'Hello world' you can print hello world in similar manner

Can someone help me with this syntax error print name.find('s')? [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 6 years ago.
I am using python 3.5.1. I have a variable called name and the value assigned is sarah. I get a syntax error when I type print name.find('s'). What am I doing wrong?
In Python 3, print() is a function and requires parentheses:
print(name.find('s'))

How to fix a syntax error with print in Python 3? [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 6 years ago.
I have installed bs4 and Python 3.4.4.
>>> print soup.prettify()
File "<stdin>", line 1
print soup.prettify()
^
Syntax Error: invalid syntax
In Python 3.x, print is a function, not a statement.
So, you want to call it as print(soup.prettify()).

Invalid string syntax error [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 8 years ago.
Why does the following code crash?
I'm following along with the tutorial, and it seems my version is a bit newer than the one I'm following. The syntax I wrote makes complete sense to me, yet claims that it's invalid syntactically:
var1 = "Hello world! "
print var1
or:
print "Hello world!"
In Python 3.x, print is a function, so you have to call it.
For example,
print('hello world')

Python Interactive Shell - SyntaxError with print [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 7 years ago.
I am new to Python.
I installed Python on my Windows 2003 Virtual Machine; Launched the Python Shell; Typed the following code -
print "Hello World"
And it spit right back at me the following
SyntaxError: invalid syntax
Here are some other following statements
>>> x = 10
>>> print x
SyntaxError: invalid syntax
The following worked fine though.
>>> x
10
Why wouldn't Python let me write a simple Hello World program?
Duh! My mistake.
print(x)
is the command.
Sorry folks!

Categories

Resources