what syntax i mine missing here please [duplicate] - python

This question already has answers here:
if/else in a list comprehension
(12 answers)
Closed 2 years ago.
mersenne_list = [mersenne_number(p) for p in the list_prime]
^
SyntaxError: invalid syntax
i entered the above code and it gave me this error, which syntax is missing, please

You need to remove the in the to just in
mersenne_list = [mersenne_number(p) for p in list_prime]
you can read more about in here

Remove the:
mersenne_list = [mersenne_number(p) for p in list_prime]
Python saw two names separated by a space which is invalid syntax.

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.

Error in python code - SyntaxError: invalid syntax [duplicate]

This question already has answers here:
Django Python Dictionary comprehension giving syntax error
(1 answer)
Alternative to dict comprehension prior to Python 2.7
(1 answer)
Closed 5 years ago.
I need to use a code written by someone else in Python a while back, and I get a SyntaxError: invalid syntax in this line:
tfileServices = {n: s.fileName for n, s in process.services.iteritems() if s.type_() == 'TFileService'}
I am not really sure what is wrong about it, so can someone tell me why is it not working (it supposedly worked for him)? Thank you! (I am not sure what to google for to find out what is wrong, as I am not sure how the actual syntax should look like)

Syntax Error in call to print [duplicate]

This question already has answers here:
Using print() (the function version) in Python2.x
(3 answers)
Closed 6 years ago.
I am currently coding a slot-like game, and everything seems to work besides this one thing:
File "/Users/r/Desktop/Game.py", line 36
print(one, end = " ")
^
SyntaxError: invalid syntax
Does anyone know how to fix this?
Are you trying to pass a Boolean for the second parameter to print?
In that case you want print(one, end == ' ')

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

Python += with a list and a tuple [duplicate]

This question already has answers here:
Why does += behave unexpectedly on lists?
(9 answers)
Why can't I add a tuple to a list with the '+' operator in Python?
(3 answers)
Closed 7 years ago.
I saw someone wrote an interesting python line online, but couldn't understand why it works. So we can try the following lines in python interpreter:
s=[1]
s=s+(1,-1)
This will result in an error "TypeError: can only concatenate list (not "tuple") to list". But if done in another way:
s=[1]
s+=(1,-1)
will result in s = [1,1,-1]
So I used to thought x=x+y is equivalent to x+=y, can someone tell me how they are different and why the second way works? Thanks in advance.
Instead of += use list.extend:
s = [1]
s.extend((1,-1))

Categories

Resources