- 论坛徽章:
- 3
|
- def do_plus(first,second):
- for param in (first,second):
- if(type(param)!=type("")) and (type(param)!=type(1)):
- raise TypeError("this funcion needs a string or an interger")
- return first+second
- a=do_plus([3],3)
- print(a)
复制代码
- [root@h6 ~]# python file
- Traceback (most recent call last):
- File "file", line 6, in ?
- a=do_plus([3],3)
- File "file", line 4, in do_plus
- raise TypeError("this funcion needs a string or an interger")
- TypeError: this funcion needs a string or an interger
复制代码 使用这个do_plus函数的参数错了,但是我只想输出TypeError: this funcion needs a string or an interger
其他的如Traceback (most recent call last):
File "file", line 6, in ?
a=do_plus([3],3)
File "file", line 4, in do_plus
不想让他输出,怎么办 |
|