I saw this code on the Internet, and I wonder what _
_
is doing with
for_in
instead of the string "_"
.
mylist = [1,1]
if True:
for _ in mylist:
print("hello world!")
hello world
hello world
These days, the trendy programming language, Go, and classical languages like Erlang, the meaning of '_' is syntax, which is used when you don't have to assign a value to a variable. From the example source code, it's easy to think that you're throwing away the element value with _ instead of using variables because you don't take and write elements as many as the number of elements in the list.
Python is usually called a 'throwaway variable'. Related Links: http://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python
Link to Golang: http://stackoverflow.com/questions/24357028/meaning-of-underscore-blank-identifier-in-go
© 2024 OneMinuteCode. All rights reserved.