Often times we want to create a list containing a continuous value like, in a range of 100-200. Let’s discuss how to create a list using the
Will this work ?
As we can see in the output, the result is not exactly what we were expecting because Python does not unpack the result of the range() function.
Code #1: We can use argument-unpacking operator i.e. *.
As we can see in the output, the argument-unpacking operator has successfully unpacked the result of the range function.
Code #2 : We can use the
extend() function to unpack the result of range function.
- Python | Numbers in a list within a given range
- Python | Create list of numbers with given range
- Python | Alternate range slicing in list
- Python | Assign range of elements to List
- Python List Comprehension | Three way partitioning of an array around a given range
- Python | Print list elements in circular range
- Python | Front and rear range deletion in a list
- Python | Find missing numbers in a sorted list range
- Python | Generate random numbers within a given range and store in a list
- Python | Convert list of tuples to list of list
- Python | Convert list of string to list of list
- Python program to create a list of tuples from given list having number and its cube in each tuple
- Python | Filter list of strings based on the substring list
- Python | Sorting list of lists with similar list elements
- Python | Add list elements with a multi-list based on index
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.