GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    Gabriel Pettier (tshirtman@mas.to)'s status on Sunday, 26-May-2024 17:37:18 JST Gabriel Pettier Gabriel Pettier
    • Tokyo Outsider (337ppm)
    • C.

    @cazabon @tokyo_0 hm, association doesn't change the result here

    >>> (not True) and True
    False
    >>> (not False) and True
    True
    >>> not (True and True)
    False
    >>> not (False and True)
    True
    >>>

    I think the question is more about the common misconception of beginner than "in" does more regarding "and" that it really does.

    "in" evaluates if the value before it is in the value after it, "and" checks that the value on both sides are true.

    A and B in C => A and (B in C)
    ≠> A in C and B in C

    In conversation Sunday, 26-May-2024 17:37:18 JST from mas.to permalink
    • Embed this notice
      Gabriel Pettier (tshirtman@mas.to)'s status on Sunday, 26-May-2024 17:59:22 JST Gabriel Pettier Gabriel Pettier
      • Tokyo Outsider (337ppm)
      • C.

      @tokyo_0 @cazabon "and" and "or" will short-circuit if the first part is enough to know the result.

      >>> def spy(value):
      ... print("called with", value)
      ... return value
      ...
      >>> spy(True) or spy(False)
      called with True
      True
      >>> spy(True) and spy(False)
      called with True
      called with False
      False
      >>> spy(False) and spy(True)
      called with False
      False

      so "in" will only be called if the value before the and is "truthy", which means that bool(value) returns True.

      In conversation Sunday, 26-May-2024 17:59:22 JST permalink
    • Embed this notice
      Gabriel Pettier (tshirtman@mas.to)'s status on Sunday, 26-May-2024 23:47:19 JST Gabriel Pettier Gabriel Pettier
      in reply to
      • Tokyo Outsider (337ppm)
      • C.

      @tokyo_0 @cazabon In python, values are generally "truthy" except for:
      - False
      - None
      - 0
      - "" (empty string)
      - [] (empty list)
      - () (empty tuple)
      - {} (empty dictionary)
      - set() (empty set)

      which are "falsy".

      Here your test probably assumes the value is True or False, but it could be something else, like either a string containing a key, or None, or a custom object or None.

      In conversation Sunday, 26-May-2024 23:47:19 JST permalink
    • Embed this notice
      Gabriel Pettier (tshirtman@mas.to)'s status on Monday, 27-May-2024 05:09:59 JST Gabriel Pettier Gabriel Pettier
      • Tokyo Outsider (337ppm)
      • C.

      @tokyo_0 @cazabon yes, the "and" will ensure the result of "in" is used if needed. the code is similar to:

      if not Ecryption.AES:
      . . . flag = False
      else:
      . . . flag = "FLAG" in stream

      but i commonly need to check/rethink if "not" affects the whole "and" expression 😅.

      regarding compile/run time, python does most things on the latter, and doesn't optimise this kind of expressions, because the language gives you too much freedom to be able to check they are valid.

      In conversation Monday, 27-May-2024 05:09:59 JST permalink

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.