List and String Functions in Python (Class 11)
1. List Functions & Methods
len(list)
Returns the number of elements in the list.
max(list)
Returns the largest element in the list.
min(list)
Returns the smallest element in the list.
sum(list)
Returns the sum of numeric elements in the list.
sorted(list)
Returns a sorted version of the list.
List Methods:
list.append(item)
Adds an item to the end of the list.
list.insert(index, item)
Inserts an item at the given index.
list.extend(iterable)
Extends the list with elements from another iterable.
list.remove(item)
Removes the first occurrence of the item.
list.pop(index)
Removes and returns the element at the given index.
list.index(item)
Returns the index of the first occurrence of an item.
list.count(item)
Counts the occurrences of an item in the list.
list.reverse()
Reverses the list in place.
list.sort()
Sorts the list in ascending order.
list.copy()
Returns a shallow copy of the list.
list.clear()
Removes all elements from the list.
2. String Functions & Methods
len(str)
Returns the length of the string.
max(str)
Returns the character with the highest ASCII value.
min(str)
Returns the character with the lowest ASCII value.
String Methods:
str.upper()
Converts all characters to uppercase.
str.lower()
Converts all characters to lowercase.
str.capitalize()
Capitalizes the first letter.
str.title()
Capitalizes the first letter of each word.
str.strip()
Removes leading and trailing spaces.
str.lstrip()
Removes leading spaces.
str.rstrip()
Removes trailing spaces.
str.replace(old, new)
Replaces occurrences of a substring.
str.find(substring)
Returns the index of the first occurrence.
str.rfind(substring)
Returns the last occurrence index.
str.count(substring)
Counts occurrences of a substring.
str.startswith(substring)
Checks if the string starts with a substring.
str.endswith(substring)
Checks if the string ends with a substring.
str.split(separator)
Splits a string into a list.
str.join(iterable)
Joins a list of strings into one string.