Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    ot : boolean operators

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 348 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 18/03/2012 at 11:58, xxxxxxxx wrote:

      this is slightly ot, but i'll be asking nevertheless :D. is there a shorter way to write the 
      following boolean expression in python ?

      if x == a or x == b or x == c :
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 18/03/2012 at 12:52, xxxxxxxx wrote:

        if x in [a, b, c]:
        

        There may be a time where you want to apply another operator or a complex comparison to a number of variables.

        if any(map(lambda v: x <= v, [a, b, c])) :
        

        Or use all() if you want the if-clause being True only when the comparison matches to every element, not any.

        if all(map(lambda v: x <= v, [a, b, c])) :
        

        You can find a listing of all built-in functions here. Note that this is the CPython 2.7 documentation. Cinema 4D embedds the 2.6 distribution and therefore there may be functions documented not availablenin C4D. (The 2.6 version of the page is here but doesn't habe such a nice table of all functions.)

        Cheers,
        -Niklas

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 18/03/2012 at 17:02, xxxxxxxx wrote:

          thanks !

          1 Reply Last reply Reply Quote 0
          • First post
            Last post