Methods of Datatypes
Methods of Datatypes
Trimillos
SLICING STRING
Slicing a string in Python allows you to extract a portion of the string. You can do this by
specifying a start and end index within square brackets after the string variable.
CONCATENATE STRING
Concatenate strings in python is the process of joining two or more strings together to create a
new string.
FORMAT STRING
Formatting strings in Python allows you to create dynamic strings by inserting values into
placeholders within a string template.
CAPITALIZE STRING
In python, you can capitalize a string using the capitalize() method. This method return a copy of
the string with the first character capitalized and the rest of the characters unchanged.
UPPER STRING
In python, you can convert a string to uppercase using upper() method. This method returns a
copy of the string with all alphabetic characters converted to uppercase.
LOWER STRING
In python, you can convert a string to lowercase using lower() method. This method returns a
copy of the string with all alphabetic characters converted to lowercase.
TITLE STRING
To convert the first character of each word in a string to uppercase, you can use the title()
method in python. This method returns a copy of the string with the first character of each word
capitalized and all other characters converted to lowercase.
REPLACE STRING
To replace occurrences of a substring within a string with another substring, you can use the
replace() method in python. The replace() method takes two arguments; the substring to be
replaced and the substring to replace it with. It returns a new string where all occurrences of the
first substring are replaced with the second substring.
COUNT STRING
The count() method in python allows you to count the number of occurrences of a substring
within a string.
CENTER STRING
The center() method in python is used to center a string within a specified width. It pads the
string with spaces (or any other specified character) on both sides to make sure it reaches the
specified width.
RIGHT JUSTIFY STRING
The rjust() method in python is used to right-justify a string within a specified width. It pads the
string with spaces (or any other specified character) on the left side to make sure it reaches the
specified width.
LEFT JUSTIFY STRING
The ljust() method in Python is used to left-justify a string within a specified width. It pads the
string with spaces (or any other specified character) on the right side to make sure it reaches the
specified width.
LENGTH STRING
To get the length of a string in python, you can use the len() function.
APPEND and EXTEND LIST
In python, you can append elements to a list using the append() method. You can also append
multiple elements to the end of a list using the extend() method.
INSERT LIST
To insert an element into a specific position in a list in Python, you can use the insert() method.
The syntax of insert() is variable(index number, element value).
REMOVE LIST
To remove an element from a list in Python, you can use the remove() method. The remove()
method removes the first occurrence of the specified value from the list. If the value is not found
in the list, it raises a ValueError. If there are multiple occurrences of the value, only the first
occurrence is removed.
DELETE LIST
The del() method is used to remove an item or slice from a list by index.
CLEAR LIST
In Python, lists have a built-in clear() method that removes all elements from the list. After
calling clear() method the list will be empty.
POP LIST
The pop() method in Python is used to remove and return the item at a specified index from a list.
If no index is specified, it removes and returns the last item in the list.
ADD SET
To add an element to a set in Python, you can use the add() method. Sets in Python are unordered
collections of unique elements, so adding an element to a set ensures that it's not a duplicate.
COPY SET
To make a copy of a set in Python, you can use the copy() method or simply create a new set
using the existing set.
REMOVE OR DISCARD SET
In Python, you can remove an element from a set using the remove() method or discard()
method.
POP SET
In Python, you can use the pop() method to remove and return an arbitrary element from a set.
Since sets are unordered collections, the specific element removed is not guaranteed and may
vary.
UNION SET
In Python, you can perform a union operation on sets using the union() method. The union of two
sets contains all distinct elements from both sets.
DIFFERENCE SET
In Python, you can find the difference between two sets using the difference() method. The
difference between two sets contains elements that are present in the first set but not in the second
set.
INTERSECTION SET
In Python, you can find the intersection of two sets using the intersection() method. The
intersection of two sets contains elements that are present in both sets.
CLEAR SET
To remove all elements from a set in Python, you can use the clear() method. This method
removes all elements from the set, leaving it empty.
FROMKEYS DICTIONARY
In Python, the fromkeys() method is used to create a new dictionary with keys from a given
iterable (such as a list or tuple) and with each key initialized to a default value, which is “None”
by default.
GET DICTIONARY
In Python dictionaries, the get() method is used to retrieve the value associated with a specified
key. It provides a way to access dictionary elements without raising an error if the key is not
found.
ITEMS DICTIONARY
In Python dictionaries, the items() method is used to return a view object that displays a list of
tuples containing the key-value pairs of the dictionary. This view object provides a dynamic view
of the dictionary's contents, reflecting any changes made to the dictionary.
KEYS DICTIONARY
In Python dictionaries, the keys() method is used to return a view object that displays a list of all
the keys in the dictionary. This view object provides a dynamic view of the dictionary's keys,
reflecting any changes made to the dictionary.
VALUES DICTIONARY
In Python dictionaries, the values() method is used to return a view object that displays a list of
all the values in the dictionary. This view object provides a dynamic view of the dictionary's
values, reflecting any changes made to the dictionary.
UPDATE DICTIONARY
In Python dictionaries, the update() method is used to update the dictionary with elements from
another dictionary or from an iterable of key-value pairs. If the key already exists in the
dictionary, the corresponding value will be updated; otherwise, a new key-value pair will be
added.
POP ITEM DICTIONARY
In Python dictionaries, the popitem() method is used to remove and return an arbitrary key-value
pair from the dictionary. This method is useful when you want to remove and process items from
the dictionary in an arbitrary order.
POP DICTIONARY
The pop() method in Python dictionaries is used to remove an item with the specified key and
return its value.
THANKYOU!