Menu
CoddyTech

Equality and Identity

Lesson 8 of 48 in Coddy's Python for Kotlin Developers course.

Kotlin == delegates to equality and === tests reference identity. Python == and is are similar in purpose, but Python is is a keyword, not Kotlin's triple equals. Lists in both languages compare contents for equality. Arrays require special attention in Kotlin because their default equality is not list-style element comparison. Compare Python strings by value rather than relying on interning or object caching.

Kotlin

fun main() {
    val a = mutableListOf(4)
    val b = mutableListOf(4)
    println(a == b)
    println(a === b)
}

Python

a = [4]
b = [4]
print(a == b)
print(a is b)

Porting trap

Python equality is not a static type check: 1 == True is true. Identity asks whether two references denote one object, not whether their printed forms match.

Complete the task in its editable modules. The locked driver.py supplies execution; keep the required API names.

challenge icon

Challenge

Beginner

Read 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__")
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Python for Kotlin Developers

Practice on your own: Online Python compiler