1. SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
问题:文件的路径输入格式不对,操作系统为 C:\Users\Administrator\Desktop\python学习笔记\QR03-turtle库v1.pdf'
但 Python等语言对转义字符标志\有意义,所以在此更改为/
2.TypeError: string indices must be integers, not str
问题:
字符串类型取第index个字符的时候,应该传入int而不是str。如
1 | a = 'abcdef' |
2 | print a[ 0 ] |
3 | #而不是 print a['0'] |
更常见的情况是把一个string当成了字典在使用 :should_be_dict_but_string['id']