• What is the reason from different output generate using logical 'and' a

    From ICT Ezy@21:1/5 to All on Sun Nov 6 22:01:08 2022
    Please explain how to generate different output in following logical operations >>> 0 and True
    0
    0 or True
    True
    1 and True
    True
    1 or True
    1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to ICT Ezy on Mon Nov 7 08:19:04 2022
    ICT Ezy <ictezy@gmail.com> writes:
    Please explain how to generate different output in following logical operations
    0 and True
    0
    0 or True
    True
    1 and True
    True
    1 or True
    1

    I call a value "x" "falsy" if "not not x" evaluates to "False";
    I call a value "x" "truthy" if "not not x" evaluates to "True".

    The evaluation of "x and y" first evaluates "x";
    If the value of "x" is falsy, then the value of "x" becomes
    the value of "x and y",
    otherwise, "y" is being evaluated, and the value of "y" becomes
    the value of "x and y".

    The evaluation of "x or y" first evaluates "x";
    If the value of "x" is truthy, then the value of "x" becomes
    the value of "x and y",
    otherwise, y is being evaluated, and the value of "y" becomes
    the value of "x and y".

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Stefan Ram on Mon Nov 7 08:36:16 2022
    ram@zedat.fu-berlin.de (Stefan Ram) writes:
    The evaluation of "x and y" first evaluates "x";

    main.py

    def evaluate( expression ):
    x, op, y = expression.split()
    if op == "and":
    x = eval( x )
    if not x:
    return x
    else:
    return eval( y )
    elif op == "or":
    x = eval( x )
    if x:
    return x
    else:
    return eval( y )

    print( evaluate( "0 and True" ))
    print( evaluate( "0 or True" ))
    print( evaluate( "1 and True" ))
    print( evaluate( "1 or True" ))

    output

    0
    True
    True
    1

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David@21:1/5 to ICT Ezy on Tue Nov 8 11:05:50 2022
    On Tue, 8 Nov 2022 at 03:08, ICT Ezy <ictezy@gmail.com> wrote:

    Please explain how to generate different output in following logical operations

    0 and True
    0
    0 or True
    True
    1 and True
    True
    1 or True
    1

    Hi,

    The exact explanation of how 'and' and 'or' behave can be read here:
    https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not The "Notes" there explain what you see.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Exam Guide Publishers@21:1/5 to David on Thu Nov 10 07:23:42 2022
    On Tuesday, 8 November 2022 at 05:36:49 UTC+5:30, David wrote:
    On Tue, 8 Nov 2022 at 03:08, ICT Ezy <ict...@gmail.com> wrote:

    Please explain how to generate different output in following logical operations

    0 and True
    0
    0 or True
    True
    1 and True
    True
    1 or True
    1
    Hi,

    The exact explanation of how 'and' and 'or' behave can be read here: https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not The "Notes" there explain what you see.
    Thank you very much, I understood Cleary.
    Before I have doubt, but now clear.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)