LIst of contents:
- Lists
- List items
- Ordered
- Changeable
- Allow Duplicates
- List length
- List items (data type)
- type()
- The list() constructor
- Python collection (arrays)
Python lists are one of the most flexible tools that you will use when you start programming. They let you store many items in one place, making it simple to organise and manage your data, you can read more on python website.
Example:
mylist = ["apple", "banana", "cherry"]
list items are the individual elements that make up a list. A list is a built in data structure that allows you to store an ordered collection of items
it means that the elements in the list maintain a specific sequence based on the order in which they were added.
refers to the mutability of an object, meaning that the object's content can be modified after it has been created.
it means that a list can contain multiple instances of the same value.
Examples:
lista = ["apple", "banana", "cherry", "apple", "cherry"]
print(lista)
list length refers to the number of items or elements it contains.
Example:
lista = ["apple", "banana", "cherry"]
print(len(lista))
refers to the types of elements that can be stored within a list. Python lists are versatile data structures that can hold items of different data types.
Example:
list1 = ["apple", "banana", "cherry"]
list2 = [1, 5, 7, 9, 3]
list3 = [True, False, False]
is used to determine the data type of an object, including the elements within a list.
Example:
mylist = ["apple", "banana", "cherry"]
print(type(mylist))
It is a built in function used to create a new list. It can take an iterable like a string, tuple, set, or another list as an argument and convert it into a list. If no argument is provided, it creates an empty list.
Example:
thislist = list(("apple", "banana", "cherry")) # note the double round-brackets
print(thislist)
- Lists:
Lists are one of the most commonly used collection types. They are mutable, ordered, and can hold items of different data types. -
Tuples:
Tuples are similar to lists but they are immutable or they cannot be changed after creation. They can also hold items of different data. - SETS:Sets are unordered collections that do not allow duplicate elements.They are useful for membership testing and removing duplicates.
- DICTIONARY:Dictionary store key-value pairs and are unordered. Keys must be unique, while values can be of any data type.