Why is the list printing 2 and not an empty string?

a. This is printing 2 because is the first assignment

b. Why is this one printing 2 and not an empty string?

Your two examples are the same.


>>> '' or 2
>>> bool(2)
>>> bool('')
1 Like

Thanks. Can you please explain as to why bool(’ ') is False an not True because we gave a value which is an empty string?

1 Like

Empty strings have a boolean value of False in most languages.

Edit: Possibly all (I don’t know all languages.)
Edit #2: Ruby is an exception. Empty strings are truthy in Ruby. There are likely others.

1 Like