Howcome a string type variable is considered as boolean in Python?

The if memo and if tags statements are checking the truthiness of the memo and tags variables Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false: None False zero of any numeric type, for example 0 0L 0.0 0j any empty sequence, for example () any empty mapping, for example {} instances of user-defined classes, if the class defines a nonzero__() or len__() method, when that method returns the integer zero or bool value False All other values are considered true — so objects of many types are always true.

The if memo and if tags statements are checking the truthiness of the memo and tags variables. Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false: None False zero of any numeric type, for example, 0, 0L, 0.0, 0j.

Any empty sequence, for example, '', (), . Any empty mapping, for example, {}. Instances of user-defined classes, if the class defines a __nonzero__() or __len__() method, when that method returns the integer zero or bool value False.

All other values are considered true — so objects of many types are always true.

But in that code there is no way entering an empty string for tags and memo variables. Which means they will always be true. Right?

– alwbtc May 13 at 14:10 1 @alwbtc: If the user hits enter right away, you get an empty string, as the newline isn't included in the return value. – delnan May 13 at 14:26.

Every object in Python has a truth value. Strings are True if they are non-empty.

It all depends on Python's version of truthiness.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions