Is there a difference between `continue` and `pass` in a for loop in python?

前端 未结 11 1371
孤街浪徒
孤街浪徒 2020-11-27 09:05

Is there any significant difference between the two python keywords continue and pass like in the examples

for element in some_list         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 09:56

    Consider it this way:

    Pass: Python works purely on indentation! There are no empty curly braces, unlike other languages.

    So, if you want to do nothing in case a condition is true there is no option other than pass.

    Continue: This is useful only in case of loops. In case, for a range of values, you don't want to execute the remaining statements of the loop after that condition is true for that particular pass, then you will have to use continue.

提交回复
热议问题