screeps-starter-python
1.0.0
1.0.0
  • Introduction
  • Logistics
    • Setup
    • Upgrading Transcrypt
  • Screeps API Usage
    • Constants
    • Optional Arguments
    • Objects - Basic Interaction
    • Objects - Creation and the Keyword "new"
  • Features
    • Console Commands
  • Lodash
    • Introduction
    • As Arguments to API Methods
  • Syntax Changes
    • Summary
    • in Opperator
    • List Behavior
    • del Operator
    • dict Iteration
Powered by GitBook
On this page

Was this helpful?

  1. Syntax Changes

in Opperator

PreviousSummaryNextList Behavior

Last updated 4 years ago

Was this helpful?

In regular python, in opreators on lists, objects, and generally any container object. It also supports overloading via the __contains__ method.

Transcrypt's in operator supports neither of these things. In order to achieve better performance when used with dicts (javascript "object"s), it behaves very similarly to JavaScript's in operator.

It will work the same on dictionaries, but does not support lists, and does not support custom containers.

To find whether a list contains an item or a string contains a sub-string, one can use the method:

# in regular python:
if ('x' in 'asdf'
        and 'the_key' in the_dict 
        and 'the_item' in the_list):
    pass
 # in Screeps via Transcrypt:
 if ('asdf'.includes('x')
         and 'the_key' in the_dict
         and the_list.includes('the_item')):
     pass
includes