2020-10-03

    科技2022-07-11  122

     

    class Car(): def __init__(self,makee,modell,yearr): self.make = makee self.model = modell self.year = yearr def get_descriptive_name(self): long_name = str(self.year) + " " + self.model + " " + self.make return long_name my_car = Car('fengtian','yueye','1928') my_car.get_descriptive_name() print("make:" + my_car.make ) print("model:" + my_car.model) print("year:" + my_car.year) r@r:~/coml/python/9/922/pro1$ python3 car.py File "car.py", line 3 self.make = makee ^ TabError: inconsistent use of tabs and spaces in indentation r@r:~/coml/python/9/922/pro1$ python3 car.py File "car.py", line 3 self.make = makee ^

    出错原因:

    TabError: Inconsistent use of tabs and spaces in indentation

    首先这个错误的意思是:在缩进的时候,使用了错误的空格和tab

    我使用的python3.5,造成这个错误的原因是我在函数里面敲if....elif 判断语句的时候,elif之前先用了空格然后再用tab完成了对齐,也就是说,这种错误产生的原因正是由于空格或者tab缩进造成的。

    然后我做了试验,将空格删除,直接使用tab完成缩进,发现程序正常运行;

    再试一下空格缩进,然后发现还是报错了,同样TabError: Inconsistent use of tabs and spaces in indentation。

     

    需要统一输入格式,要不全用tab缩进,要不全用空格,不统一,会报错

    Processed: 0.009, SQL: 8