0

Syntax for Lists

What is the syntax for creating lists in Python? For eg in JAVA we use: <datatype> <variable name> []= new <variable name> [<array size>]

6th Jul 2017, 6:22 PM
Arpan Sircar
Arpan Sircar - avatar
7 Réponses
+ 13
According to : https://www.sololearn.com/Course/JUMP_LINK__&&__Python__&&__JUMP_LINK/?ref=app Lists are another type of object in Python. They are used to store an indexed list of items.  A list is created using square brackets with commas separating items.  The certain item in the list can be accessed by using its index in square brackets.  For Example : words = ["Hello", "world", "!"] print(words[0]) print(words[1]) print(words[2]) Output : >>> Hello world ! >>>
6th Jul 2017, 6:27 PM
Dev
Dev - avatar
+ 1
I am not quite sure if I got you well but here is a method of converting a number that you have from being integer to be in a list that can have strings or integers as the below x=2356 n=123 y=list (str(x)) print(y) z=[int(x) for x in str(n)] print (z)
6th Jul 2017, 8:59 PM
Mohamed Raouf
Mohamed Raouf - avatar
+ 1
what do you mean by "user-defined list" ? both Dayve's and my answers are the closest we can give you with your question
6th Jul 2017, 9:18 PM
Amaras A
Amaras A - avatar
+ 1
There is no way to limit the size of a LIST in Python. To do that, you need another data type.
7th Jul 2017, 7:17 AM
Amaras A
Amaras A - avatar
0
I don't think you got what I asked. What I asked was that how could we create user-defined lists?
6th Jul 2017, 7:10 PM
Arpan Sircar
Arpan Sircar - avatar
0
words = ["Hello", "world", "!"] there you go, from @Dayve's message
6th Jul 2017, 8:19 PM
Amaras A
Amaras A - avatar
0
By user defined list, I mean a list whose size is pre-defined by the user. Like they do in JAVA.
7th Jul 2017, 12:36 AM
Arpan Sircar
Arpan Sircar - avatar