Criado por Aparna Dhirde
mais de 4 anos atrás
|
||
Questão | Responda |
Lists | A list is a data structure in Python that is mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Lists are defined by having values between square brackets [ ] |
Lists are Mutable | It means that the contents of the list can be changed after it has been created. |
List Operations | Concatenation,Repetition, Membership,Slicing |
Concatenation | Allows us to join two or more lists using concatenation operator depicted by the symbol +. |
Repetition | Allows us to replicate a list using repetition operator depicted by symbol *. |
Membership | membership operators in checks if the element is present in the list and returns True, else returns False. |
Slicing | Slicing is used to extract a part of the list. |
Built-in Functions | built-in functions are defined as the functions whose functionality is pre-defined in Python |
len() | Returns the length of the list passed as the argument |
list() | Creates an empty list if no argument is passed .Creates a list if a sequence is passed as an argument |
append() | Appends a single element passed as an argument at the end of the list The single element can also be a list |
extend() | Appends each element of the list passed as argument to the end of the given list |
insert() | Inserts an element at a particular index in the list |
count() | Returns the number of times a given element appears in the list |
index() | Returns index of the first occurrence of the element in the list. If the element is not present, ValueError is generated |
remove() | Removes the given element from the list. If the element is present multiple times, only the first occurrence is removed. If the element is not present, then ValueError is generated |
pop() | Returns the element whose index is passed as parameter to this function and also removes it from the list. If no parameter is given, then it returns and removes the last element of the list |
reverse() | Reverses the order of elements in the given list |
sorted() | It takes a list as parameter and creates a new list consisting of the same elements arranged in sorted order |
min() | Returns minimum or smallest element of the list |
max() | Returns maximum or largest element of the list |
sum() | Returns sum of the elements of the list |
sort() | Sorts the elements of the given list in-place |
Nested Lists | When a list appears as an element of another list, it is called a nested list. |
Quer criar seus próprios Flashcards gratuitos com GoConqr? Saiba mais.