Commonly used Python functions and methods:
### STRING FUNCTIONS:
-
len(): Returns the length of a string.
-
str.upper(): Converts a string to upper-case.
-
str.lower(): Converts a string to lower-case.
-
str.capitalize(): Capitalizes the first character of a string.
-
str.split(): Splits a string into a list.
-
str.join(): Joins elements of a list into a string.
-
str.replace(): Replaces a specified phrase with another specified phrase.
-
str.strip(): Removes whitespace from the beginning and end of a string.
### LIST FUNCTIONS:
-
len(): Returns the length of a list.
-
list.append(): Adds an item to the end of the list.
-
list.extend(): Adds the elements of a list (or any iterable) to the end of the current list.
-
list.insert(): Adds an item at a specified position.
-
list.remove(): Removes the first item with the specified value.
-
list.pop(): Removes the item at the specified position.
-
list.index(): Returns the index of the first element with the specified value.
-
list.sort(): Sorts the list.
-
list.reverse(): Reverses the order of the list.
### DICTIONARY FUNCTIONS:
-
dict.keys(): Returns a list of all the keys in the dictionary.
-
dict.values(): Returns a list of all the values in the dictionary.
-
dict.items(): Returns a list of tuples, each tuple containing a key and a value.
-
dict.get(): Returns the value of the specified key.
-
dict.update(): Updates the dictionary with the specified key-value pairs.
-
dict.pop(): Removes the element with the specified key.
### TUPLE FUNCTIONS:
-
len(): Returns the length of a tuple.
-
tuple.count(): Returns the number of times a specified value appears in a tuple.
-
tuple.index(): Searches the tuple for a specified value and returns the position of where it was found.
### SET FUNCTIONS:
-
len(): Returns the length of a set.
-
set.add(): Adds an element to the set.
-
set.remove(): Removes the specified element.
-
set.union(): Returns a set containing the union of sets.
-
set.intersection(): Returns a set containing the intersection of sets.
-
set.difference(): Returns a set containing the difference of sets.
-
set.symmetric_difference(): Returns a set with elements in either the set or the specified set, but not both.
### NUMERIC FUNCTIONS:
-
abs(): Returns the absolute value of a number.
-
round(): Rounds a number to a specified number of digits.
-
max(): Returns the largest item in an iterable.
-
min(): Returns the smallest item in an iterable.
-
sum(): Sums the items of an iterable.
### DATE AND TIME FUNCTIONS (datetime module):
-
datetime.datetime.now(): Returns the current date and time.
-
datetime.datetime.today(): Returns the current local date.
-
datetime.datetime.strftime(): Formats a datetime object as a string.
-
datetime.datetime.strptime(): Parses a string to a datetime object.
### FILE I/O FUNCTIONS:
-
open(): Opens a file and returns a file object.
-
file.read(): Reads the contents of a file.
-
file.write(): Writes data to a file.
-
file.readlines(): Reads all the lines of a file into a list.
-
file.close(): Closes the file.
### GENERAL FUNCTIONS:
-
print(): Prints to the console.
-
input(): Reads a string from standard input.
-
type(): Returns the type of an object.
-
isinstance(): Checks if an object is an instance of a class or a tuple of classes.
-
id(): Returns the identity of an object.
Here you can find essential Python Interview Resources👇
https://whatsapp.com/channel/0029VaGgzAk72WTmQFERKh02
Like this post for more resources like this 👍♥️
Share with credits:
https://t.me/sqlspecialist
Hope it helps :)