shadowing
Using a name that already means something, such as list or str, for your own variable, which hides the original in that part of the program.
Hiding a built-in or a module causes confusing errors far from the line that caused them.
In more detail
It is legal but unwise: after list = [1, 2], calling list("abc") fails because list now means your list. The same happens to a module when you name your own file random.py or math.py. Choose another name, such as items.
Related terms
- Python built-in function — A function that is always available in Python without importing anything, such as print, len, input, int and range.
- module search path — The list of folders Python searches, in order, when a program imports a module.
- identifier — A name for a thing in code, such as a variable, function or module name.
Taught in
- How Python Runs Your Code — Hands-on Python: Complete Video Course & Book
- Editors, IDEs And Shells — Hands-on Python: Complete Video Course & Book
- Where Python Lives: PATH And Versions — Hands-on Python: Complete Video Course & Book
- Sample Graphics Programs — Hands-on Python: Complete Video Course & Book
- Entry Objects — Hands-on Python: Complete Video Course & Book
- Thirty Questions, One Sneaky Print — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Fundamentals Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Control Flow Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Try, Except, Else And Finally — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- The Class That Shared One List — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Import Variants, dir() And sys.path — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Class Variables, Instance Variables And __dict__ — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Object-Oriented Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Twelve Traps, Mostly Objects — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Mock, Review And Exam Day — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep