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>]
7 Respuestas
+ 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
!
>>>
+ 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)
+ 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
+ 1
There is no way to limit the size of a LIST in Python.
To do that, you need another data type.
0
I don't think you got what I asked. What I asked was that how could we create user-defined lists?
0
words = ["Hello", "world", "!"]
there you go, from @Dayve's message
0
By user defined list, I mean a list whose size is pre-defined by the user. Like they do in JAVA.