print('kk' and '') #вывод пустая строка print('' or 'gh') #gh print('' or [] or {}) #{} f = 'first' s = 'second' print(1 and f or s) #first print(0 and f or s) #second 

    1 answer 1

    The result of the and and or operators in Python is not defined as True or False .

    It is equal to the first or second operand .

    It is precisely this one whose logical value must be further determined so that the ordinary result of a logical operation is already familiar from a mathematical point of view (ie, True or False ).

    (See. Documentation 6.11. Boolean operations .)

    For example, in your first line

     'kk' and '' 

    the logical value 'kk' is determined first - this is True since the string is not empty. (See 4.1. Truth Value Testing .)

    This is not enough for the evaluation of any logical expression (it would be enough if it were False ), and so the logical value of the second operand , '' -, of the last, must still be defined , and so it will be the result of your expression 'kk' and '' .