girls-in-ai / Girls-In-AI

免费学代码系列:小白python入门、数据分析data analyst、机器学习machine learning、深度学习deep learning、kaggle实战
http://girls-in-ai.github.io/Girls-In-AI/
3k stars 477 forks source link

转义字符语法错误 EOL while scanning string literal #54

Open yfu6 opened 4 years ago

yfu6 commented 4 years ago

**Is your feature request related to a problem? Please describe. 数据类型教程中的转义字符代码部分,打出 I'm a GIAer. I'm learning machine learning by 'python'.这两句话时,显示语法错误 File "", line 1 print('I\'m a GIAer.\nI\'m learning machine learning by\'Python'') ^ SyntaxError: EOL while scanning string litera

Describe the solution you'd like 说出你的解决建议 把开头结尾的‘改成双引号之后问题解决,可以正常输出 print("I\'m a GIAer.\nI\'m learning machine learning by\'Python'")

Gakiii commented 3 years ago

print('I'm a GIAer.\nI'm learning machine learning by'Python'')

在单引号前面加反斜杠也可以 , 因为你用‘ 作为字符串包含的话,前面的一个’ 就会被当作字符串结束符号 所以I‘m的'也要转义一下