The is Keyword Changes Meaning
Lesson 8 of 48 in Coddy's Python for GDScript Developers course.
GDScript is checks whether a value has a type or inherits a class. Python is instead asks whether two references denote the same object. Use isinstance for a Python type check, == for value equality, and is None for absence. Two separately created Python lists can have equal contents and distinct identities. GDScript array equality also compares contents, while object comparison needs its own identity/value design.
GDScript
extends SceneTree
func _init():
var a = [4]
var b = [4]
print(a == b)
print(a is Array)
quit()Python
a = [4]
b = [4]
print(a == b)
print(a is b)Porting trap
A direct port of value is SomeClass changes meaning in Python: it compares value with the class object itself. Use isinstance(value, SomeClass) for the intended type relationship.
Complete the task in its editable modules. The locked driver.py supplies execution; keep the required API names.
Challenge
BeginnerRead two text labels on separate lines. The reserved token missing means an absent label; all other lines, including an empty line, are actual strings. The scaffold converts that token to None. Print whether the labels have equal values, then whether the first is absent, then whether the second is absent, one Python boolean per line.
Print only these lines, ending each with a newline. Keep the supplied input scaffold; it reads the stated values without prompts.
Your code goes in main.py. The locked driver.py starts your program and cannot be edited.
Try it yourself
# Starts the program in main.py. Edit main.py to solve the challenge.
from runpy import run_module
run_module("main", run_name="__main__")
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Python for GDScript Developers
1From GDScript to Python
Run Your First Python ProgramPrint Is Not printsVar, Const, and BindingsInteger Division DifferencesSimilar Indentation, New ScopeRecap: Rewrite a Receipt4Iteration and Transformations
Ranges and RebindingItems and enumerateWhile and Early ExitArray Callbacks and KeysRecap: Build a Ranking2Values and Decisions
Null and NoneThe is Keyword Changes MeaningLogical Results and OperandsConditional ExpressionsRecap: Eligibility Rules3Collections and Shared State
Array and List APIsArrays, Vectors, and TuplesDictionary Lookup RulesDuplicate and Shallow CopyRecap: Clean an Inventory6Input, Errors, and Modules
Console Work Outside GodotValidation and ExceptionsScript Resources and ImportsTyped GDScript and AnnotationsRecap: Validate a Batch9Project: Order Processing
Create the Order ModelAdd Pricing PoliciesPractice on your own: Online Python compiler