Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Shadowing a Built-in Function (Part 1, 4: Arithmetic operations)

Open Beginner friendly
#62 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
62/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
documentation

Research direction

Locate the lesson containing the shown Python arithmetic example and run the snippet, including the commented-out initialization, to observe the built-in shadowing behavior. Update the example and explanation so the accumulator uses a non-shadowing name such as total_sum, while preserving the explanation of the resulting error.

Written by the indexing model from the issue text.

Description

sum = 0

number = int(input("First number: "))
sum = sum + number

number = int(input("Second number: "))
sum = sum + number

number = int(input("Third number: "))
sum = sum + number

print(f"The sum of the numbers: {sum}")

As you may well be aware, sum is a built-in function in Python (used for adding up items in lists, etc.). While Python allows us to use sum as a variable name, it "shadows" the built-in function, which can lead to confusing bugs later in our code. It is safer to use a name like total_sum instead.

For example, comment out the first line and try to run the code. It should result in a NameError, but it raises a TypeError instead. Why? A NameError only occurs when Python cannot find a name anywhere (not in our local variables, global variables, or built-in functions). Because # sum = 0 was commented out, Python didn't find sum as a variable, but it did find the pre-existing built-in function sum() that comes built into Python. Therefore, it didn't raise a NameError.

--

Thank you for this wonderful course!

Dominant language
JavaScript
Stars
78
Forks
28
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rage/programming-26

All issues in rage/programming-26

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.