Methods and Functions

Python Standard Library Reference

Python is an object-oriented programming language that may be extended and interpreted. It is capable of running a wide range of programs, from simple text processing scripts to interactive WWW browsers. Python standard library is extremely comprehensive, providing a wide range of facilities, as evidenced by the lengthy table of contents listed below. This library reference handbook describes the Python standard library as well as a number of optional library modules. Some of these modules are expressly meant to encourage and improve Python program portability by abstracting away platform-specifics into platform-neutral APIs.

Python Built-in Functions

Python built-in functions are types of functions whose functionalities are pre-defined by the programming language. The Python programming language includes a number of functions that are readily available for use. These are known as built-in functions. All of Python’s built-in functions are listed on this reference page.

Functions Description
abs() Absolute value of a number is returned
all() Returns true when all the elements in the argument are true
any() Checks if any Element of an iterable is True
ascii() Returns String Containing Printable Representation
bin() Converts an integer to binary string
bool() Converts a Value to Boolean data type
bytearray() An array is returned of the specified byte size
bytes() This function returns an immutable bytes object
callable() Checks if the Object is Callable
chr() Returns a Character (a string) from an Integer
classmethod() Returns class method for a given function
compile() Returns a Python code object
complex() A Complex Number is created
delattr() Attribute From the Objects are deleted
dict() A Dictionary is created
dir() Tries to Return Attributes of Object
divmod() Returns a Tuple of Quotient and Remainder
enumerate() An Enumerate Object is returned
eval() Runs Python Code Within Program
exec() Executes Dynamically Created Program
filter() Constructs iterator from elements that are true
float() Returns a floating-point number from number, string
format() Returns formatted representation of a value
frozenset() Returns an immutable frozen-set object
getattr() Returns value of named attribute of an object
globals() Returns dictionary of current global symbol table
hasattr() This function returns whether an object has a named attribute
hash() This function returns a hash value of an object
help() This function helps to Invokes the built-in Help System
hex() Converts an Integer value to Hexadecimal
id() Returns Identify of an Object
input() Reads and returns a line of string
int() Returns an integer from a number or string
isinstance() Checks if an Object is an Instance of Class
issubclass() Checks if the Class is a Subclass of another Class
iter() Returns an iterator
len() Prints the Length of an Object
list() Creates a list in Python
locals() Returns dictionary of a current local symbol table
map() Applies Function and Returns a List
max() Returns the largest item from the iterator
memoryview() Returns memory view of an argument
min() Returns the smallest value from the iterator
next() Retrieves next item from the iterator
object() Creates a featureless object
oct() Prints the Octal representation of an Integer
open() Returns a file object
ord() Returns an integer of the Unicode character
pow() Prints the power of a number
print() Prints the Given Object after the program has been run
property() Returns the property attribute
range() Return sequence of integers between start and stop parameter
repr() Returns a printable representation of the object
reversed() Prints the reversed iterator of a sequence
round() Rounds off a number to the specified decimals
set() Constructs and returns a set
setattr() Sets the value of an attribute of an object
slice() Returns a slice object
sorted() A sorted list is returned from the given iterable
staticmethod() Transforms a method into a static method
str() Returns the string version of the object
sum() Adds items of an Iterable
super() Returns a proxy object of the base class
tuple() An iterator is converted into a tuple and printed
type() Returns the data type of the object
vars() Returns the __dict__ attribute
zip() Returns an iterator of tuples
__import__() Function called by the import statement

Python Dictionary Methods

Python dictionary provides a variety of methods and functions that can be used to easily perform operations on the key-value pairs. Let us look at the Python standard library references for various dictionary methods that are listed below.

Method Description
clear() Removes all the elements from the dictionary
copy() Returns a shallow copy of the specified dictionary
fromkeys(seq, val) Creates a new dictionary with keys from seq and val assigned to all the keys
get(key) Returns the value of the specified key
has_key() Returns True if the key exists in the dictionary, else returns False
items() Returns a list of dictionary’s items in (key, value) format pairs
keys() Returns a list containing all the keys in the dictionary
pop(key) Removes and returns an element from a dictionary having the given key
popitem() Removes and returns an arbitrary item (key, value).
setdefault(key, val) Returns the corresponding value if the key is in the dictionary. If not, insert the key with a value of val
update() Updates the dictionary by adding key-value pair
values() Returns a list containing all the values in the dictionary

Python List Methods

The methods accessible with list objects in Python programming are listed below. They are referred to as list.method(). Now, the Python standard library references for lists are:

Methods Description
append() Adds a single element to the end of the list
clear() Removes all the elements from the list
copy() Returns a shallow copy of the list
count() Returns the number of items specified as a parameter
extend() Adds multiple elements to the end of the list
index() Returns the index value of the first matched item
insert() Inserts an item at the specified index position
pop() Returns and removes an element at the specified index
remove() Removes a specified item from the list
reverse() Reverses the order of the entire list
sort() Sorts all the items in an ascending order

Python Set Methods

Just like Python string, list, and dictionary class methods, the set() function also has different methods that are used for performing various operations on the data elements.

Method Description
frozenset() Returns an immutable frozenset object
Set add() Adds elements to the set
Set clear() Deletes all the elements from the set
Set copy() Returns a copy of the set
Set difference() Returns the difference between 2 or more sets
Set difference_update() Updates the calling set by removing the items that are also included in the other specified sets
Set discard() Removes a specific element from the set
Set intersection() Returns an intersection of 2 or more sets
Set intersection_update() Updates the calling set by removing the items that are not present in the other specified sets
Set isdisjoint() Returns whether 2 sets have an intersection or not
Set issubset() Returns whether one set contains this set or not
Set issuperset() Returns whether this set contains another set or not
Set pop() Removes an arbitrary element
Set remove() Removes the specified element from the set
Set symmetric_difference() Returns symmetric differences of 2 or more sets
Set symmetric_difference_update() Updates the Set with symmetric difference
Set union() Returns union of sets
Set update() Adds elements to the set

Python String Methods

Because Python Strings are immutable, all of these functions return a new string while leaving the previous string untouched and unchanged. The Python standard library references for strings are:

Method Description
String capitalize() Returns a string with the first character converted to Uppercase while other letters to lowercase
String casefold() Returns a string converting a wider range of characters to lowercase
String center() Pads the input string to the center with a specified character
String count() Returns the number of occurrences of a substring from the original string
String encode() Returns an encoded string with the specified encoding standard
String endswith() Returns value TRUE if the string ends with the specified suffix
String expandtabs() Replaces tab characters \t with spaces
String find() Returns the index value of the first occurrence of the substring
String format() Formats the string by converting it into a more representative output format
String format_map() Formats the string values using a dictionary
String index() Returns the index value of the substring specified
String isalnum() Checks if all characters are alphanumeric
String isalpha() Checks if all characters are alphabets
String isdecimal() Checks if all characters are decimal values
String isdigit() Checks if all characters are digits or not
String isidentifier() Checks if all characters are valid identifiers
String islower() Checks if all characters in a string are lowercased
String isnumeric() Checks if all characters are numeric
String isprintable() Checks if all characters are printable
String isspace() Checks if all characters contain whitespaces
String istitle() Returns TRUE if the string is a title cased string
String issuper() Returns TRUE if all the characters in the string are uppercase
String join() Returns a concatenated string
String ljust() Returns a left-justified string as per the width specified
String lower() Converts all the characters of the string to lowercase
String lstrip() Returns a string with the leading characters removed
String maketrans() Create a mapping table and returns this translation table
String partition() Splits the string at the first occurrence of the separator
String replace() Replaces all the occurrences of the specified substring with another substring
String rfind() Returns the highest index value of the substring
String rindex() Returns the highest index value of the substring inside the string
String rjust() Returns a right-justified string as per the width specified
String rpartition() Splits the string into 3 different parts and returns a tuple
String rsplit() Splits the string from right
String rstrip() Returns a string with all the trailing characters removed
String split() Splits the string from the specified separator and returns a list
String splitlines() Splits the string at line boundaries
String startswith() Returns value TRUE if the string starts with the specified prefix
String strip() Removes both the leading and trailing characters of a string
String swapcase() Swaps uppercase characters to lowercase and vice versa
String title() Converts the string to a tile cased string
String translate() Modifies the string according to the translation table
String upper() Converts all the characters of the string to uppercase
String zfill() Returns a copy of the string with ‘0’ padded to the left of the string

Python Tuple Methods

Python standard library references for tuples are:

Function Description
cmp(tuple1, tuple2) Compares elements of both the tuples
len(tuple) Returns the total length of the tuple
max(tuple) Returns the largest element from the tuple
min(tuple) Returns the smallest element from the tuple
tuple(seq) Converts a list into a tuple
count() Returns count of the element in the tuple

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

avatar
  Subscribe  
Notify of

Customize your course in 30 seconds

Which class are you in?
No thanks.