造成这个错误的原因是:语句缩进时,Tab键和空格键混合使用了!
Python错误:缩进方式混用 TabError: Inconsistent use of tabs and spaces in indentation
Python默认以第一行缩进为准,如上面程序中的:
Python错误:缩进方式混用 TabError: Inconsistent use of tabs and spaces in indentation
假如“guess”使用的缩进时四个空格,那么后面的缩进都要用打4个空格的方法;若是“guess”使用的缩进时按一次Tab键,则后面的缩进全要用Tab键。

如何坚持缩进的方式:把光标放在缩进语句的最开头,Python错误:缩进方式混用 TabError: Inconsistent use of tabs and spaces in indentation
按"Backspace"键,假如’guess’只往前缩了一格(有时字体会变颜色),说明guess的缩进方式是四个空格
Python错误:缩进方式混用 TabError: Inconsistent use of tabs and spaces in indentation
假如
仅按一次
"Backspace"键,直接回到了顶格,说明缩进方式的按Tab键。

出现上述错误时,只需让缩进方式统一(全部空格键或Tab键),就能解决错误!

补充:系统默认的缩进是四个空格,也就是:假如写
for i in range(1,21):
回车后的缩进的方式,系统给的是4个空格(用上面讲到的Backspace键可以验证。)

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2021-09-06
  • 2021-10-02
  • 2021-06-13
  • 2021-06-15
猜你喜欢
  • 2021-06-04
  • 2022-01-13
  • 2021-09-12
  • 2021-11-22
  • 2021-07-12
  • 2021-12-25
相关资源
相似解决方案