mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-11-26 20:34:32 +03:00
Merge pull request #4491 from smith558/patch-3
[python/en] Clarify casting and move bool() function section
This commit is contained in:
commit
e6f2e1420c
@ -85,12 +85,24 @@ False - 5 # => -5
|
|||||||
2 == True # => False
|
2 == True # => False
|
||||||
-5 != False # => True
|
-5 != False # => True
|
||||||
|
|
||||||
|
# None, 0, and empty strings/lists/dicts/tuples/sets all evaluate to False.
|
||||||
|
# All other values are True
|
||||||
|
bool(0) # => False
|
||||||
|
bool("") # => False
|
||||||
|
bool([]) # => False
|
||||||
|
bool({}) # => False
|
||||||
|
bool(()) # => False
|
||||||
|
bool(set()) # => False
|
||||||
|
bool(4) # => True
|
||||||
|
bool(-6) # => True
|
||||||
|
|
||||||
# Using boolean logical operators on ints casts them to booleans for evaluation, but their non-cast value is returned
|
# Using boolean logical operators on ints casts them to booleans for evaluation, but their non-cast value is returned
|
||||||
# Don't mix up with bool(ints) and bitwise and/or (&,|)
|
# Don't mix up with bool(ints) and bitwise and/or (&,|)
|
||||||
bool(0) # => False
|
bool(0) # => False
|
||||||
bool(4) # => True
|
bool(2) # => True
|
||||||
bool(-6) # => True
|
|
||||||
0 and 2 # => 0
|
0 and 2 # => 0
|
||||||
|
bool(-5) # => True
|
||||||
|
bool(2) # => True
|
||||||
-5 or 0 # => -5
|
-5 or 0 # => -5
|
||||||
|
|
||||||
# Equality is ==
|
# Equality is ==
|
||||||
|
Loading…
Reference in New Issue
Block a user