Tensorflow:SyntaxError: unexpected character after line continuation character

created at May 21, 2021, 8:36 a.m. views: 0

Problem description

For example, editing two lines of code:

tf.keras.layers.MaxPooling2D((2, 2), strides = 2),\ 
 tf.keras.layers.Conv2D(64, (3, 3), padding = 'same',activation = tf.nn.relu)

There seems no problem on the appearance, but according to the error display SyntaxError: unexpected character after line continuation character
Let’s take a look:
Is there a space after the newline character \ in the first line? The answer is yes, that's reason why the program will report an error. 

Solution

Delete the space and the problem is solved.
Also note that not to add things after the \  , such as a # comment.

Please log in to leave a comment.