ChardScript List
call myList = ["apple", "banana", "cherry"]List
Lists are used to store multiple items in a single variable.
Lists are created using square brackets:
Example
Create a List:
call thisList = ["apple", "banana", "cherry"]
echo(thisList)List Items
List items can add new item values, extend list to list and allow duplicate values.
List items are indexed, the first item has index [0], the second item has index [1] etc.
Append
To appends an element to the end of the list, use append() function:
Example
call theList = ["Hello World!"]
append(theList, "Hi World!")
echo(theList)
# Output: Hello World!, Hi World!Extend
To add the specified list elements (or any iterable) to the end of the current list, use extend() function:
Example
Allow Duplicates
Since lists are indexed, lists can have items with the same value:
Example
List Length
To determine how many items a list has, use the length() function:
Example
List Items - Data Types
List items can be of any data type:
Example
String, int and boolean data types:
A list can contain different data types:
Example
A list with strings, integers and boolean values:
Last updated