0

while declaring a variable with string in python i'm getting the below error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

data_path ='C:\Users\amjin\My_datasets\simple-examples\data'
AK47
  • 8,646
  • 6
  • 37
  • 61

1 Answers1

0

try to write your path on this way :

data_path ='C:/Users/amjin/My_datasets/simple-examples/data'

You can change \ with /

or:

In Python 3, you can avoid this by using a raw string:

data_path =r'C:\Users\amjin\My_datasets\simple-examples\data'

The backslash ( \ ) character is used to escape characters that otherwise have a special meaning, such as newline, backslash itself, or the quote character.

example:

in your path: 'C:\Users\amjin\My_datasets\simple-examples\data'

'\a' : ASCII bell makes ringing the bell alert sounds
print ("\a") , result :N/A

ncica
  • 6,737
  • 1
  • 14
  • 33