Set, String and Dictionary data type method in python
Set: A Set is an unordered collection of unique elements enclosed within curly braces {}.
Common Set Methods:
add() – Adds an element to the set.
pop() – Removes a random element.
remove() – Removes a specified element (raises an error if not found).
discard() – Removes a specified element (does not raise an error if not found).
union() – Combines two sets.
intersection() – Returns common elements.
difference() – Returns elements present in one set but not in another.
symmetric_difference() – Returns elements present in either set but not both.
isdisjoint() – Checks whether two sets have no common elements.
issubset() – Checks whether a set is a subset of another set.
issuperset() – Checks whether a set is a superset of another set.
Output
String Data Type
A String is a sequence of characters enclosed within single quotes ' ' or double quotes " ".
Common String Methods
upper() – Converts all characters in the string to uppercase.
lower() – Converts all characters in the string to lowercase.
capitalize() – Converts the first character of the string to uppercase.
title() – Converts the first character of each word to uppercase.
swapcase() – Converts uppercase letters to lowercase and lowercase letters to uppercase.
replace() – Replaces a specified substring with another substring.
split() – Splits the string into a list based on a separator.
rsplit() – Splits the string from right to left.
partition() – Splits the string into three parts at the first occurrence of a separator.
rpartition() – Splits the string into three parts at the last occurrence of a separator.
startswith() – Checks whether the string starts with a specified value.
endswith() – Checks whether the string ends with a specified value.
find() – Returns the index of the first occurrence of a substring.
rfind() – Returns the index of the last occurrence of a substring.
index() – Returns the index of a substring (raises an error if not found).
count() – Returns the number of occurrences of a substring.
join() – Joins elements of an iterable using the string as a separator.
strip() – Removes leading and trailing spaces.
lstrip() – Removes leading spaces.
rstrip() – Removes trailing spaces.
isupper() – Checks whether all characters are uppercase.
islower() – Checks whether all characters are lowercase.
isalpha() – Checks whether all characters are alphabets.
isalnum() – Checks whether all characters are alphanumeric.
isnumeric() – Checks whether all characters are numeric.
zfill() – Adds zeros at the beginning of the string until it reaches a specified length.
removeprefix() – Removes a specified prefix from the string.
removesuffix() – Removes a specified suffix from the string.
Output
Dictionary Data Type
A Dictionary is a collection of data stored in key-value pairs enclosed within curly braces {}
Output