Flat 10% & upto 50% off + 10% Cashback + Free additional Courses. Hurry up
×
UPTO
50%
OFF!
• Live Instructor-led Classes
• Expert Education
• 24*7 Support
• Flexible Schedule

Lists are Python’s most flexible ordered collection object type. A list can be created by putting the value inside the square bracket and values are separated by comma.

```<list name>=[value1,value2,...,value n];
```

Unlike strings, lists can contain any sort of object: numbers, strings, even other lists. Python lists are:

• Ordered collections of arbitrary objects
• Accessed by offset
• Arrays of object references
• Variable length, heterogeneous, arbitrarily nestable
• Of the category mutable sequence
• The elements are stored in the index basis with starting index as 0.
• A python list is enclosed between square([]) brackets.

e.g.

```list1 = [1,2,3,4,5];

list2=["hello","intellipaat"];
```

Accessing Lists

To access list following syntax is used:

```<list name>[index]
```

e.g.

`list1 = [1,2,3,4,5];`

print list1[2]

Output

3

Operations on List

On list following operation are performed:

• Concatenate List

+ Operator is used to concatenate two lists.

```L1 = [1, 2, 3, 4]

L2 = [5, 6, 7, 8]

print L1+L2
```

Output

[1, 2, 3, 4, 5, 6, 7, 8]

• Replicate Lists

Operator * is used to repeat a list by specific number of time.

```L1=[1,2]

print L1*2
```

Output

[1,2, 1, 2]

• Sub List

It is used to obtain a sub list which is done by specifying the index.

```L1 = [1,2,3,4]

print L1[0:3]
```

Output

[1, 2, 3]

• Update List

For this purpose assign the value to the index of the list.

```L1 = [1, 2, 3, 4]

L1[0] = 0

print L1
```

Output

[0, 2, 3, 4]

• Deletion

To delete value from list del is used.

```L1 = [1, 2, 3, 4]

del L1[0]

print L1
```

Output

[2, 3, 4]

Functions and Methods in List

 min(list_name) Returns the minimum value from the list max(list_name) Returns the largest value from the list. len(list_name) Returns number of elements in a list. cmp(list1,list2) Compares the two lists. list.reverse() Reverse the list list.sort Sort the list list(sequence) Covert the sequence into the list list.append(value) Add the value into the list list.remove(value) Remove the value from the list
Previous Next

Learn SQL in 16 hrs from experts

"0 Responses on Python Lists"

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

Sales Offer

• To avail this offer, enroll before 11th December 2018.
• This offer cannot be combined with any other offer.
• This offer is valid on selected courses only.
• Cashback will be accumulated in Intellipaat e-wallet
• Please use coupon codes mentioned below to avail the offer