![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python报错
Polaris_GQ
这个作者很懒,什么都没留下…
展开
-
if__name__==‘__main__‘ : ^ SyntaxError: invalid syntax报错
# -*- coding = utf-8 -*-# @Author:Polaris# @File:spider.py# @Software:PyCharmdef main(a): print("hello",a)main(2)if __name__=="__main__": #当程序执行时 #if和__name__之间有空格,否则SyntaxError: invalid syntax main(1)#错误示例:if__name__=="__main__":#正确示例:原创 2022-03-04 10:27:45 · 3369 阅读 · 0 评论 -
python中出现IndentationError:unindent does not match any outer indentation level错误
例子:IndentationError:unindent does not match any outer indentation level缩进错误:缩进级别不匹配原创 2022-02-14 16:41:16 · 441 阅读 · 0 评论 -
Python的Keyboard Interrupt问题
例子:问题:KeyboardInterrupt:键盘中断(异常处理)一般是循环无限进行下去所导致的原创 2022-02-14 17:45:34 · 23811 阅读 · 1 评论 -
Python的AttributeError: ‘list‘ object has no attribute ‘len‘
while i<school.len():#错误属性错误::‘list’对象没有属性’len’换句话说,就是列表school没有方法len()while i<len(school):#正确原创 2022-02-14 22:26:33 · 6156 阅读 · 0 评论 -
TypeError: ‘int‘ object is not iterable
for i in len(products):改为:for i in range(len(products)):即可TypeError: ‘int’ object is not iterable该问题的原因是:不能直接用int进行迭代,而必须使用range方法,即range(x).原创 2022-02-14 22:48:46 · 1300 阅读 · 0 评论 -
解决python中TypeError: not enough arguments for format string
import randomcomputer=random.randint(0,2)admin=int(input("请用户输入:"))if admin==0: h="剪刀"elif admin==1: h="石头"else: h="布"print("你的输入为:%s(%d)"%h%admin))print("随机生成数字为:%d"%computer)if admin<0 or admin>2: print("Error")else: if原创 2022-02-12 21:56:58 · 28731 阅读 · 0 评论 -
Python报错:TypeError:not supported between instances of ‘str‘ and ‘int‘
1)报错原因:字符串(str)未转化便和整数(int)进行比较2)解决办法:转换即可#错误:name = input(‘我是小hi,请问你叫什么名字?\n’)age = input(‘我8岁了,你呢?\n’)if(age < 30):print(f"你才{age}啊!")print(“你真年轻,如花似玉的年龄!”)#正确:name = input(‘我是小hi,请问你叫什么名字?\n’)age = input(‘我8岁了,你呢?\n’)age = int(age)if(a.原创 2022-03-02 08:38:55 · 6170 阅读 · 0 评论