Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Built in Functions and methods in Python

The document outlines built-in functions and methods for strings, lists, and dictionaries in Python. It provides a comprehensive list of functionalities for each data type, including string manipulation methods like 'str()', 'count()', and 'replace()', as well as list methods such as 'append()', 'sort()', and dictionary methods like 'get()' and 'keys()'. This serves as a reference for Python programming, detailing how to manipulate these common data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Built in Functions and methods in Python

The document outlines built-in functions and methods for strings, lists, and dictionaries in Python. It provides a comprehensive list of functionalities for each data type, including string manipulation methods like 'str()', 'count()', and 'replace()', as well as list methods such as 'append()', 'sort()', and dictionary methods like 'get()' and 'keys()'. This serves as a reference for Python programming, detailing how to manipulate these common data structures.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Built in Functions and methods in Python

Strings Methods :

Function Format Functionality

str(string) Converts an object into a string

Converts the first letter of each word to uppercase


string.title() and the rest to lowercase
( title format )

string.count(Sub_string) Returns the number of occurrences of a substring


in the string

string.split(delimiter) Splits the string into a list based on a delimiter


(default is whitespace)

string.lower() Converts all characters to lowercase

string.upper() Converts all characters to uppercase

string.strip() Removes leading and trailing whitespace

string.replace(Str1 , Str2) Replaces a substring with another substring

string.find(Sub_string) Returns the index of the first occurrence of a


substring. Returns -1 if not found

string.startswith(prefix) Checks if the string starts with the specified prefix


Returns True if the string starts with the prefix,
otherwise False
string.endswith(suffix) Checks if the string ends with the specified suffix
Returns True if the string starts with the prefix,
otherwise False

string.isdigit() Checks if all characters in the string are digits


Returns True if the string contains only digits,
otherwise False

Lists Methods :

list.append(elem) Adds an element to the end of the list

list.insert( position , elem) Inserts an element at a specified index

list.remove(elem) Removes the first occurrence of a specified


element

list.pop(elem) Removes and returns the element at the specified


index (default is last element)

list.index(elem) Returns the index of the first occurrence of a


specified element

list.sort() Sorts the list in place (modifies the original list)

list.reverse() Reverses the elements of the list in place

len(list) Returns the length (number of elements) of the


list

sum(list) Returns the sum of all elements in the list


(if they are numeric)

Dictionary Methods :

dict.get(key) Returns the value for the specified key, or a


default value if the key doesn't exist
dict.keys() Returns a view object displaying a list of all keys in
the dictionary

dict.values() Returns a view object displaying a list of all values


in the dictionary

dict.items() Returns a view object displaying a list of


key-value pairs in the dictionary

del dict [key] Removes a key-value pair from the dictionary

You might also like