Practical use of booleans | SoloLearn: Learn to code for FREE!

0

Practical use of booleans

What is the practical use for these types?

8/30/2019 1:49:49 AM

Andrew Johnson

5 Answers

New Answer

+5

A flag is nothing official in a programming language. I found this short definition in techterms.com: In computer science, a flag is a value that acts as a signal for a function or process. The value of the flag is used to determine the next step of a program. Flags are often binary flags, which contain a boolean value (true or false). ... A common example of a flag in computer programming is a variable in a while loop. A flag can be stored in a variable so it holds just one information. But flags can also be stored in data structures like lists or dictionaries. An example for this can be used if you have to check a user input against some conditions the input should have. So if you have to check if a password meets a length of min 5 and max 10 characters, and it also needs to have at least on digit you can store each result of all this things as a flag. Let's have a dict like this: results = { "length" : True, "digit" : True, ... } So you can do all necessary checks and store the result in the appropriate place. If you have done all these checks, you can see with all() or any() if your dict meets all conditions of user input (pass or fail).

+6

i=0 found=False while found==False and i<max: if a[i]==item: found=True else: i+=1

+5

+4

Thank you for your time, i just learned if and elif statements so i will learn about it soon because i don't understand what you are talking about now lol.

+3

I guess I have not come across flags yet. What exactly are they?