What is the equivilent of a python list in pixilang?

Pixilang programming language
Post Reply
philipbergwerf
Posts: 174
Joined: Sat Mar 17, 2018 4:23 pm

What is the equivilent of a python list in pixilang?

Post by philipbergwerf »

What is the equivilent of a python list in pixilang?
A python list looks like this:

Code: Select all

mylist = [1, 2, 3, 4]
and you can access the items like so:

Code: Select all

firstitem = mylist[0]
seconditem = mylist[1]
etc = mylist[2]
Is there something similar in pixilang?
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: What is the equivilent of a python list in pixilang?

Post by NightRadio »

There is no direct alternative.
But you can use the arrays:

Code: Select all

mylist = new( 4, 1, INT )
mylist[ 0 ] = 1
mylist[ 1 ] = 2
mylist[ 2 ] = 3
mylist[ 3 ] = 4
firstitem = mylist[ 0 ]
seconditem = mylist[ 1 ]
philipbergwerf
Posts: 174
Joined: Sat Mar 17, 2018 4:23 pm

Re: What is the equivilent of a python list in pixilang?

Post by philipbergwerf »

Thank you for the clear example!
9912
Posts: 17
Joined: Sat Oct 15, 2016 8:09 pm

Re: What is the equivilent of a python list in pixilang?

Post by 9912 »

Hi and sorry for necroposting, but python lists can store also strings inside them.
So the other question is: how to store an array of text in pixilang like this? (python code)

Code: Select all

mylist = ["one string","another string","another string"]
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: What is the equivilent of a python list in pixilang?

Post by NightRadio »

9912 wrote: Sat Jul 09, 2022 9:51 am how to store an array of text in pixilang like this?

Code: Select all

mylist = new(3,1,INT)
mylist[0] = "one string" //store string container ID (integer)
mylist[1] = "another string"
mylist[2] = "another string"
Post Reply