Avatar ·

for _ in Range. How does an underscore work

📁 Advanced Python Topics, example

  MATRIX = [[ 0 ]* 5 ]  for  _  in   range  ( 5 )]  
  

there is such an expression, creates five such elements 0 0 0 0 0 . Who can explain the mechanics of creating, the simpler the better.

for example

   for  x  in   range  ( 5 ):   print  (x)   

range(5) is 0,1,2,3,4

and for each value starting from the first (0), the action is performed