Need Assistance?

support@tutorialshub.in

Collections and Strings

Strings

ADVERTISEMENT
Python Free Lesson
5 min read
ADVERTISEMENT

Lists store ordered mutable data

Lists are the standard choice when you need an ordered collection that can grow or change. They support indexing, slicing, iteration and methods for adding, removing and sorting values.

Important list operations

append() adds one value, extend() adds multiple values, insert() places a value at a position, pop() removes and returns an item, and remove() deletes the first matching value.

References and copying

Assigning one list to another variable does not copy the data; both names reference the same list. Use copy() for a shallow copy and understand that nested mutable objects are still shared.

Practice: build a shopping cart, add and remove products, calculate its total and create a sorted view without unexpectedly changing the original order.

ADVERTISEMENT