#IndentationError:expected an indented #block 缩进错误
#解决办法 tab 缩进
for index in range(10):
if name == '小王':
print('nothing')
else:
print('nothing')
name ='小王'
age = 16
print('我的名字是'+name+'我的年龄是'+age)
#TypeError:must be str,not int
#类型错误
#解决办法 使用拼接的时候 必须是字符串 或#者数字转换成字符串
count = 0
while True:
count+=1
if count ==20:
return
#SyntaxError:'return'outside function
#return 不能在方法以外使用
#解决办法:把 return放在方法以内使用
content = 'hello world'
result = content.index('r')
print(result)
#ValueError:substring not found
#值错误 子字符串未找到
content ='hello world'
print(content[21])
#IndexError:string index out of range
#索引错误 字符串的长度超出了范围
#解决办法 查看字符串的长度 索引要小于长度
list1 = ['autman','小李子','诺兰','皮克斯']
print(list[5])
#TypeError:'list'object is not callable
#索引错误 列表索引超出范围
tp1 = ((),[],{},1,a,3.14,True)
tp1.remove(1)
#AttributeError:'tuple'object has no attribure 'remove'
#属性错误 元组对象没有属性'remove'
dic1 = {
'name':'张三',
'age':17,
'friend':['李四','王五','赵六']
}
#KeyError:'fond'
#key 键错误 没有指定的键值'fond'
print(dic1['fond'])
dic1.pop()
#TypeError:pop expected at least 1 argument,got 0
#argument 参数 expected 期望 at least 至少
#类型错误:pop方法希望得到至少一个参数 但是现在参数为0
date = date1.strftime('%y 年%m月 %d日 %H时 %M分 %S秒')
# UnicodeEncodeError: 'locale' codec #can't encode character '\u5e74' in #position 3: Illegal byte sequence
# 编码错误:本地文件不能对指定位置的字符进行编码
#解决方法:用replace进行代替
date2 = date2.replace('year','年').replace('month','月').replace('day','日')
print(date2)