F string prefix in python giving a syntax error [duplicate] - python

This question already has answers here:
f-strings giving SyntaxError?
(7 answers)
Closed 5 years ago.
I have a variable called method, it's value is POST but when I try to run print(f"{method} method is used.") it keeps giving a syntax error at the last double quote and I can't find the reason on why it does this. I am using python 3.5.2.

F-strings were a new feature introduced in Python 3.6, so of course they're not going to work in 3.5.2.

Related

What is the Python ` symbol [duplicate]

This question already has answers here:
What do backticks mean to the Python interpreter? Example: `num`
(3 answers)
Meaning of the backtick character in Python
(2 answers)
Closed 1 year ago.
Lots of old python code I look in has this ` symbol around a lot of stuff, what does it do? Now it is not considered valid syntax, obviously.
And I don't think it is just another string identifier, its sometimes wrapped around functions in the code I'm looking at.
Any help will be appreciated.

does do while loop exist in python? [duplicate]

This question already has answers here:
How to emulate a do-while loop?
(20 answers)
Closed 2 years ago.
Recently came to be in need of do while loop in python, but couldn't find the syntax for it or does it even exist?
I tried below, but am getting syntax errors:
do{
#c0d3 h3r3
} while(1=1)
or:
do:
#c0d3 h3r3
while (1=1)
Can anyone tell me the syntax for it or tell me if it don't exist in python?
I am in python3 django.
Python doesn't have do-while loop, and you are assigning a value in your loop not comparing

Python " ".join() syntax error [duplicate]

This question already has answers here:
Why is parenthesis in print voluntary in Python 2.7?
(4 answers)
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 6 years ago.
I haven't done much with Python, but the code-academy course has seemed to give me some enjoyment however when I have taken my project to the actual python compiler I get an error compiling. Highly possible that code-academy just hasn't updated to a more recent version, as I've seen here that people have used this previously.
C:\Python>battleship.py
File "C:\Python\battleship.py", line 10
print " ".join(row)
^
SyntaxError: invalid syntax
For some reason I am having issues placing the source in the question, as this is my first question, so ill describe the code. Using an empty list there is a "board" created to play battleship on, with a for loop that loops through a set range appending < board.append["O"] * 5 >. Then it loops through each row in the array and then uses < print " ".join(row) >
How can I get by this and is there an alternative way that is better?
Edit: Python version 3.5.2

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'))

Showing Syntax Error while try to output the dictionary or a list value [duplicate]

This question already has answers here:
Syntax error on print with Python 3 [duplicate]
(3 answers)
Closed 9 years ago.
I am a amature in Python,using the python33 version.The problem i am facing while i want to get output of a list of dictionary just like that.
dict = {'name':'Tanvir','Position':'Programmer'};
print dict['name'];
if i run the code then there showing a syntax error.same thing is happening for the list also.
Please help me to fix the problem.
Thanks in advance.
In Python 3, print is a function, so you need print(dict[name]). You also don't need the semicolons. You also need to read the Python tutorial to learn the basics first.

Categories

Resources