0

I am new to python.. and I have seen this statement

    ['a' for i in range(10)]

My question is in general, how could I have know that such a line is possible in python for generating an array? I don't understand how come the loop is at the end? Does this have a name?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Ziad
  • 1
  • 2
  • List comprehension! One of the coolest parts of Python linguistically. – Carl Shiles Jun 15 '17 at 15:09
  • To address the "how could I have know that such a line is possible in python" part of the question: Poke around the tutorial and documentation to find any topics that look useful. Read the [python documentation on SO](https://stackoverflow.com/documentation/python/topics). You can also learn a lot by being active on SO or other python forums. – Aran-Fey Jun 15 '17 at 15:11
  • BTW -- please try to make a question title specific to that question. SO isn't a discussion forum, it's a knowledgebase -- that means every historical question we've ever had should be something people with the same question can easily find and reuse, and part of being findable/reusable (even if just as a pointer to a duplicate entry) is having a descriptive title unique to the question. – Charles Duffy Jun 15 '17 at 15:47
  • That's a very stupid way to perform `["a"] * 10`, tho. – zwer Jun 15 '17 at 16:07

0 Answers0