• Register
2 votes


I have a simple python program I wrote recently. But unfortunately, I can’t compile and run my program. It shows me an error “syntaxerror: keyword can't be an expression
Where I am being wrong in my program? Any idea?

The snippet is attached below:

name = input("Please put your name here ")

if name == "Gavin": print(name + " is a Gentleman!")

else: print(name + " I don't know him and " + name = " Who is he? ") 

Thanks, guys.

12 7 7
15,250 points

Please log in or register to answer this question.

2 Answers

1 vote


You’ve made the mistake in your else part. When you wrote:

else: print(name + " I don't know him and " + name = " Who is he? ") 

the program is trying to assign a new string under a variable in a print line. That’s not possible man. You need to use the name as a variable and put the = as part of the String.

else: print(name + " I don't know him and " + name + = " Who is he? ") 

Now, this looks good and should run fine.

13 9 6
94,240 points
0 votes


sum.up is not a valid keyword argument name. Keyword arguments must be valid identifiers. You must look in the documentation of the library you are using how this argument really is called – maybe sum_up

I guess many of us who came to this page have a problem with Scikit Learn, one way to solve it is to create a dictionary with parameters and pass it to the model:

params = {'C': 1e9, 'gamma': 1e-07}
cls = SVC(**params)    

It's python source parser failure on sum.up=False named argument as sum.up is not valid argument name (you can't use dots -- only alphanumerics and underscores in argument names).

At the time you are using the Elastic search DSL API, you may hit the same error with

s = Search(using=client, index="my-index") \
    .query("match", category.keyword="Musician")

You can solve it by doing:

s = Search(using=client, index="my-index") \
    .query({"match": {"category.keyword":"Musician/Band"}})

I just got that problem when converting from % formatting to .format().

Previous code:


Problematic syntax:


The problem is that format is a function that needs parameters. They cannot be strings. 

Corrected code:


The line below is wrong. You are using "=" sign as if you were assigning name to a new string within the print function. Doesn't work that way.

else: print(name + " sleeps all night and " + name = " works all day!")

Try it like this.

You need to use name as a variable and put the = as part of the String.

else: print(name + " sleeps all night and " + name + "= works all day!")

This worked for me in the interpreter

>>> name = input("What's your name? ")
What's your name? Ryan
>>> if name == "Kenneth": print(name + " is a lumberjack and he's OK!")
... else: print(name + " sleeps all night and " + name + "= works all day!")
Ryan sleeps all night and Ryan= works all day!

You have to use == which is the equality operator, not a single = which is the assignment operator (for example a = 1 assigns the value 1 to the variable a). In addition, you can also shorten your expression by having the comparison as the first argument and dropping the Value field.

test_reclass = Float(Con("cpraster3.tif" == 1, 0.27, Con("cpraster3.tif" == 2, 1.00, Con("cpraster3.tif == 3, 2.9, Con("cpraster3.tif" == 4, etc...


10 6 4
31,120 points

Related questions

0 votes
1 answer 5 views
Problem: In a python program I am making, I want it to only take integers, and if it gets a string say "There has been an error in the system." instead of murmering sensless information the user will not understand
asked Jan 11 Mashhoodch 5.7k points
0 votes
1 answer 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
1 vote
1 answer 175 views
Problem: Hello programmers, I hope you all are doing good in this hard time of Covid-19. I am under lockdown inside my house for more than two months. I was being mad. I decided to learn something new in these days. Therefore, I come to an end with the decision of ... mine that don&rsquo;t work var = 123 123 = roy print(var) print(123) Please, review the codes and help this beginner to walk ahead.
asked May 31, 2020 adamSw 11.3k points
0 votes
1 answer 30 views
Hello house, I would like to know how to solve this Python SyntaxError: Non-ASCII character '\xe2' in file. Thanks
asked Oct 23, 2020 psandprop 2.4k points
0 votes
2 answers 795 views
Problem : Currently I am using the Python 3.3 and I have only entered these 3 below lines: import sklearn as sk import numpy as np import matplotlib.pyplot as plt But I am facing below error: “SyntaxError: multiple statements found while compiling a single statement” What is wrong with my Python code?
asked Jan 14, 2020 jwilliam 3.9k points
0 votes
1 answer 96 views
I am new to java programming . I wrote a code in java programming language to start my projcet of learning java: public class Main { public static void main(String[] argv){ int 2count, h-l, a/b, } } But it gives me errors like : exception in thread "main" java.lang ... Syntax error on token ",", ;expected at Main.main(Main.java:3) Why am I getting this errors can anyone help me out to solve this?
asked Mar 12, 2020 LizzyM 6.1k points
0 votes
2 answers 424 views
Problem : I want to read my .csv file into Python (Spyder) but I am facing the error. Please find below my code : import csv mydata = open("C:\Users\miche\Documents\school\jaar2\MIK\2.6\vektis_agb_zorgverlener") mydata = csv.reader(mydata) print(mydata) I face the following error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
asked Dec 6, 2019 alecxe 7.5k points
1 vote
1 answer 71 views
Problem: My code isn't running. In the console the error is &ldquo;Uncaught SyntaxError: missing ) after argument list&rdquo; but there are no missing ) I find. Here is my code below: var nav = document.getElementsByClassName('nav-coll'); for (var n = 0; n < button.length; n ... function(){ console.log('haha'); } }, false); }; I&rsquo;d be thankful to him if somebody pulls me up from here. Thanks.
asked Mar 9, 2020 Gavin 15.3k points
1 vote
1 answer 41 views
Problem: I tried to pass the kwargs as a dictionary so I wrote this code: class All(object): otp_wait = 25 def __init__(self, surname, birthdate, mobile_no, otp_host, **kwargs): kwargs.setdefault('browser', 'chrome') self.surname = surname self. ... otp_host, **input_kwargs) ^ SyntaxError: positional argument follows keyword argument Can anyone help me out to solve this thing. Thanks in advance.
asked Jun 7, 2020 samhaz 5k points