Python Forum
SyntaxError: invalid character in identifier
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SyntaxError: invalid character in identifier
#1
Hello,
complete newbie here. Was practicing on pycharm and can't figure out why I'm getting such a rudimentary error. Please see below. Any feedback would be greatly appreciated. Thank you in advance.

add = ​3 ​+ ​2
sub = ​5 ​- ​4
mult = ​5 ​* ​2
div = ​7 ​/ ​2
power = ​4 ​** ​2
mod = ​7 ​% ​5
print (add, sub, mult, div, power, mod)



below is what happens when I run the code:

add = ​3 ​+ ​2
^
SyntaxError: invalid character in identifier

Process finished with exit code 1
Reply
#2
You manged some how to get \u200 zero width space Unicode character in all calculation.
>>> s = 'add = ​3 ​+ ​2'
>>> repr(s)
"'add = \\u200b3 \\u200b+ \\u200b2'"
Copy code under and run,then should be okay.
add = 3 + 2
sub = 5 - 4
mult = 5 * 2
div = 7 / 2
power = 4 ** 2
mod = 7 % 5
print(add, sub, mult, div, power, mod)
Output:
5 1 10 3.5 16 2
Reply
#3
thank you so very much! I's working fine now
I'm unclear though on what I did to cause the error and is there a way to correct the \u200 width space issue permanently as you pointed out?
thanks again!
really appreciate it
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SyntaxError: invalid syntax ?? korenron 15 5,741 Jan-25-2022, 11:46 AM
Last Post: korenron
  [solved] unexpected character after line continuation character paul18fr 4 3,405 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  [split] SyntaxError: invalid syntax Code_X 3 2,759 May-04-2021, 05:15 PM
Last Post: Yoriz
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 2,735 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  Graph identifier samuelbachorik 4 2,662 Oct-04-2020, 01:25 PM
Last Post: scidam
  SyntaxError: unexpected character after line continuation character siteshkumar 2 3,181 Jul-13-2020, 07:05 PM
Last Post: snippsat
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,857 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  SyntaxError: invalid syntax windows11 5 4,791 Mar-26-2020, 11:15 AM
Last Post: windows11
  Function: SyntaxError: invalid syntax vejin 2 2,349 Feb-02-2020, 09:25 PM
Last Post: ThiefOfTime
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 2,741 Jan-05-2020, 11:50 AM
Last Post: vivekagrey

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020