[CentralOH] _ for variables that are never referenced

jep200404 at columbus.rr.com jep200404 at columbus.rr.com
Wed Feb 25 01:41:55 CET 2015


On Sat, 21 Feb 2015 11:49:13 -0500, jep200404 at columbus.rr.com wrote:

> for _ in range(n):  # For when the loop variable is never referenced.

    Python examples

        >>> from random import randint
        >>> for _ in range(5):
        ...     print randint(0, 10-1)
        ...
        8
        4
        7
        4
        1
        >>> [randint(0, 10-1) for _ in range(5)]
        [0, 9, 2, 2, 9]
        >>>

    Go

        Using _ for name of unused variables is standard practice in Go.
        The _ is called the blank identifier.

        Joe Shaw address this in his presentation. 
        For example, see line 267 of
        https://github.com/joeshaw/talks/blob/master/cohpy/zen.slide

            for _, row := range table { ...


More information about the CentralOH mailing list