第一二行我看了半天觉得没问题,但运行显示符号错误。改成三四行的代码就没问题,有大佬知道我一二行代码哪里有问题吗
print('参数类型为list,输出结果为{}'.format(result1))
print('参数类型为tuple,输出结果为{}'.format(result2))
print(result1)
print(result2)
print('参数类型为list,输出结果为{}'.format(result1))
print('参数类型为tuple,输出结果为{}'.format(result2))
print(result1)
print(result2)
2021-04-20
def func(X):
s1=0
s2=1
if isinstance(X,list):
for i in X:
if not isinstance(i,str):#no :
s1+=i#indentation
continue
return s1
if isinstance(X,tuple):
for i in X:
if not isinstance(i,str):
s2=s2*i
continue
return s2
L=[1,2,'l',3]
T=(1,2,'t',3)
result1=func(L)
result2=func(T)
print('参数类型为list,输出结果为{}'.format(result1))
print('参数类型为tuple,输出结果为{}'.format(result2))
print(result1)
print(result2)
def func(X): s1=0 s2=1 if isinstance(X,list): for i in X: if not isinstance(i,str):#no : s1+=i#indentation continue return s1 if isinstance(X,tuple): for i in X: if not isinstance(i,str): s2=s2*i continue return s2L=[1,2,'l',3]T=(1,2,'t',3)result1=func(L)result2=func(T)print('参数类型为list,输出结果为{}'.format(result1))print('参数类型为tuple,输出结果为{}'.format(result2))print(result1)print(result2) File "index.py", line 21 SyntaxError: Non-ASCII character '\xe5' in file index.py on line 21, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
举报