underscore variable
The name _, used by convention for a value you must receive but will never use, as in for _ in range(3).
In more detail
Python treats _ as an ordinary name; the underscore only tells readers that the value is deliberately ignored. In the interactive shell _ also holds the last result shown.
Example
for _ in range(3):
print("Hip hip hooray!")Related terms
- loop variable — The name in a for heading that takes each item of the sequence in turn, as item in for item in items.
- repeat loop — A for loop over range(n) whose only purpose is to run its block n times.
Taught in
- Repeat Loops And Successive Modification — Hands-on Python: Complete Video Course & Book
- Chapter One In One Sitting — Hands-on Python: Complete Video Course & Book
- A Standard Library Tour — Hands-on Python: Complete Video Course & Book
- Lists: Slices, Methods And Aliases — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Collections Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- math, random And platform — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- List Comprehensions, Filtered And Nested — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Generators And Iterators — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- read, readline, errno And bytearray — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep