Home  >  Article  >  Backend Development  >  What does flag mean in python?

What does flag mean in python?

(*-*)浩
(*-*)浩Original
2019-07-20 09:19:0846929browse

flag in python generally means mark or identification

What does flag mean in python?

For example: (recommended learning:Python video tutorial)

#!/usr/bin/python<br># -*- coding: UTF-8 -*-<br>x = 7<br>i = 1<br>flag = 0<br><br>while i <= 100:<br>    if (x%2 == 1) and (x%3 == 2) and (x%5 == 4) and (x%6==5):<br>        flag = 1<br>    else:<br>        x = 7 * (i+1) # 根据题意,x一定是7的整数倍,所以每次乘以7<br>    i += 1<br><br>if flag == 1:<br>    print('阶梯数是:', x)<br>else:<br>    print('在程序限定的范围内找不到答案!')<br>

Output result:

阶梯数是: 119<br>

flag is used as the judgment condition of if, The original value is 0, When the if statement in while is satisfied, flag=1, that is, x is found that satisfies the condition of the if statement, and then the loop is jumped out.

flag is used as a flag . If x is found that satisfies the condition, Then the correct x will be output in the following if-else statement, otherwise it means that

was not found. For more Python related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of What does flag mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn