0

size of elements in python

In C++ and C, we decide the length of an array by typing, arr[10] , indicating 10 array elements, starting from 0 to 9. Similarly how to decide about number of elements in list in case of python ? I want list of 10 elements.

22nd Jun 2019, 10:01 AM
mohan borkar
mohan borkar - avatar
1 Answer
0
In python the size of the list can change dynamically, you do not need to declare upfront. But if you need a list of 10 elements, you can do for example: ten = list(range(10)) ten2 = [0 for i in range(10)] First one just give you digits from 0 to 9 and second one is a list comprehension resulting in 10 zeros.
22nd Jun 2019, 10:08 AM
Tibor Santa
Tibor Santa - avatar