本文主要是介绍Python中if if else和 if elif else区别,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
if if else:执行完第一个if还会去判断下一个if是否满足,不满足则会执行else,即当i==’)’, stack pop弹出之后,还会去执行stack.append()
stack = []
for i in s:if len(stack)==0:stack.append(i)continueif i==')' and stack[-1]=='(':stack.pop()if i=='}' and stack[-1]=='{':stack.pop()if i==']' and stack[-1]=='[':stack.pop()else:stack.append(i)
if elif else, 则在if满足之后不会去执行elif和else中的内容
stack = []
for i in s:if len(stack)==0:stack.append(i)continueif i==')' and stack[-1]=='(':stack.pop()elif i=='}' and stack[-1]=='{':stack.pop()elif i==']' and stack[-1]=='[':stack.pop()else:stack.append(i)
这篇关于Python中if if else和 if elif else区别的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!