Menu
CoddyTech

Variables Without let or const

Lesson 3 of 48 in Coddy's Python for JavaScript Developers course.

Bind names to values and update them without declaration keywords.

JavaScript

let retries = 2;
const saved = retries;
retries = "done";
console.log(saved);
console.log(retries);

Python

retries = 2
saved = retries
retries = "done"
print(saved)
print(retries)

What changes

These complete programs print 2 and then done. Python assignment uses the name followed by =; there is no preceding let or const. The right side is evaluated before the name is bound. A later assignment can bind that name to a different type of value, as the number-to-string change shows. Use descriptive names such as retry_count; underscores conventionally separate words. Names are case-sensitive, so total and Total are different. A name must be assigned before you read it. Here, saving an integer value under another name preserves that value when the first name is rebound. Mutable collections will need a separate discussion later.

Common mistake

Uppercase spelling, such as MAX_RETRIES, signals a constant by convention. Python does not reject reassignment because a name is uppercase. JavaScript const prevents rebinding, so removing the keyword also removes that enforcement.

Your task

Preserve the original status before accepting its replacement. Do not print the replacement twice or assume that reassigning one string name changes another.

challenge icon

Challenge

Beginner

Read two lines: an initial status and a replacement status. Keep the initial value in original, reassign status to the replacement, then print the original value and current value on separate lines. Both lines can be empty. The input scaffold reads the replacement into replacement.

Print only the requested output, with a newline after each line. The supplied input lines read the test data; keep them and add your work below.

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 JavaScript Developers

Practice on your own: Online Python compiler