我有上述错误s1="一些很长的字符串............"
有人知道我哪里做错了吗?
我有上述错误s1="一些很长的字符串............"
有人知道我哪里做错了吗?
当前回答
在我的例子中,我忘记了('或")在字符串的末尾。例如“ABC”或“ABC”
其他回答
在我使用Mac OS X的情况下,我有以下声明:
model.export_srcpkg(platform, toolchain, 'mymodel_pkg.zip', 'mymodel.dylib’)
我得到了错误:
File "<stdin>", line 1
model.export_srcpkg(platform, toolchain, 'mymodel_pkg.zip', 'mymodel.dylib’)
^
SyntaxError: EOL while scanning string literal
当我改为:
model.export_srcpkg(platform, toolchain, "mymodel_pkg.zip", "mymodel.dylib")
它工作…
大卫
在这种情况下,三单报价或三双报价都可以! 例如:
"""Parameters:
...Type something.....
.....finishing statement"""
OR
'''Parameters:
...Type something.....
.....finishing statement'''
我也遇到过类似的问题。我有一个字符串,其中包含Windows中的文件夹路径,例如C:\Users\问题是\是一个转义字符,所以为了在字符串中使用它,你需要再添加一个\。
错误:C:\Users\
正确的:C: \ \ \ \用户
你没有在一行的末尾加上“”。
如果你想这样做,使用""":
""" a very long string ......
....that can span multiple lines
"""
在我的例子中,我使用Windows,所以我必须使用双引号而不是单引号。
C:\Users\Dr. Printer>python -mtimeit -s"a = 0"
100000000 loops, best of 3: 0.011 usec per loop