List Data Type

suggest change

A list contains items separated by commas and enclosed within square brackets []. Lists are similar to arrays in C. One difference is that all the items belonging to a list can be of different data types.

list = [123,'abcd',10.2,'d']    #can be an array of any data type or a single data type.
list1 = ['hello','world']
print(list)    #will output the whole list. [123, 'abcd', 10.2, 'd']
print(list[0:2])    #will output the first two elements of the list. [123, 'abcd']
print(list1 * 2)    #will give list1 two times. ['hello', 'world', 'hello', 'world']
print(list + list1)    #will give the concatenation of both lists. [123, 'abcd', 10.2, 'd', 'hello', 'world']

The name list shadows the built-in.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents