Posts

Showing posts with the label list

What is List in Python?

 A list is a data structure used to store multiple values in a single variable . Example: numbers = [10, 20, 30, 40] names = ["Kavi","Arjun","Ashok" Values are arranged by index number starting from 0. You can print a value based on its position / index. names = ["kavi","arjun","akash"] print(names[0]) It will print the 0 index value of names list.  Lists are changeable (mutable). You can update the old value with new value in List using index number. person_details = ["John", 25, "Europe"] person_details[1]= 26 print(person_details) Can store different data types in the same list person_details = ["John", 25, 76.5, True]

Methods of List Object in Python

[] is the symbol we use in Python to create a list . A list can hold multiple items of any type (numbers, strings, even other lists ) and we can add, remove, or access items using their position (index). List has some built-in Methods because it’s an object, the ones you often use are methods like: append() – add an item to the end of the list extend() – add multiple items at once insert() – insert item at a specific position remove() – remove a specific item pop() – remove item by index sort() – sort the list reverse() – reverse the list count() – count how many times a value appears index() – find index of a value