python raise & assert

def CheckValue(value):
	value = int(value)
	#assert condiction, expression
	#当 condition为True的时候,程序不会assert,当condition判断的条件为False时候,程序就会assert
	assert value>0, "你输入的值小于0,出现错误,程序中断(assert)"
	print("程序正常运行")
	return value+1

CheckValue(8)

  程序正常运行

 

name = 2
if name == 1:
	print("yes")
else:
	raise Exception("error")

  error

python raise & assert

上一篇:c盘文件删除


下一篇:Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.