print('参数类型为list,输出结果为{}'.format(result1))
print('参数类型为tuple,输出结果为{}'.format(result2))
print(result1)
print(result2)
在最顶部加上下面的代码
# coding: utf-8
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