The following will print 'ok':
'ok'
if 5: print('ok')
But when I do this:
print(5 == True)
Output signal False.
False
The same thing happens with strings. Why?
Here you test different things.
ifjust checks if the expression of the boolexpression (see also "Checking the value of truth" ) is Truenot if the identity is equal True.
if
bool
True
So what is actually verified if:
>>> bool(5) == True True
True 1. True = 5 ( python 2), True. "if" , , 0 , 0 . False 0.
True = 5
Source: https://habr.com/ru/post/1681189/More articles:Automatically add HasCallStack restrictions for all my functions - haskellThere is official Oracle documentation saying that we should not use java.util.Date in a new project - javaКак отключить уведомления по всему миру в визуальном студийном коде - visual-studio-codeполучить тип данных столбца, используя pyspark - apache-spark? operator in C # does not compile for an unknown reason - c #C ++ compilation new warning filter - c ++consul containers with protocol version error - dockerCreating IdentityPool with CloudFormation - amazon-cloudformationWhy string = '0' is not strictly equal to the new String ('0') in javascript - javascriptHow to create a world map with Unity? - unity3dAll Articles