6/28/25, 10:32 PM Python Built-in Data Type Methods
Python Built-in Data Type Methods
Comprehensive Reference Guide
String Methods (str) immutable
[Link]()
Returns a copy of the string with all characters converted to lowercase.
s = "Hello World"
print([Link]()) # hello world
[Link]()
Returns a copy of the string with all characters converted to uppercase.
print([Link]()) # HELLO WORLD
[Link]()
Removes any leading and trailing whitespace.
[Link] nloads/python_project.html 1/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
s = " Hello World "
print([Link]()) # "Hello World"
[Link](sep)
Splits the string into a list where each word is a list item.
print([Link](" ")) # ['Hello', 'World']
[Link](sub)
Returns the lowest index of the substring if found; otherwise returns -1.
print([Link]("World")) # 7
[Link](old, new)
Replaces occurrences of a substring with another substring.
print([Link]("World", "Python"))
List Methods (list) mutable
[Link](x)
Adds an item to the end of the list.
lst = [1, 2, 3]
[Link](4) # [1, 2, 3, 4]
[Link] nloads/python_project.html 2/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
[Link](i, x)
Inserts an item at a specified position.
[Link](1, 1.5) # [1, 1.5, 2, 3, 4]
[Link](x)
Removes the first occurrence of the item.
[Link](2) # [1, 1.5, 3, 4]
[Link]([i])
Removes and returns the item at the given position.
item = [Link](1) # item = 1.5
# lst = [1, 3, 4]
[Link]()
Sorts the list in place.
[Link]() # [1, 3, 4]
[Link]()
Reverses the elements of the list in place.
[Link]() # [4, 3, 1]
[Link] nloads/python_project.html 3/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
Dictionary Methods (dict) mutable
[Link](key[, default])
Returns the value for key if exists, otherwise returns default.
d = {'a': 1, 'b': 2}
print([Link]('a')) # 1
print([Link]('c', 0)) # 0
[Link]()
Returns key-value pairs as tuples.
print([Link]()) # dict_items([('a', 1), ('b', 2)])
[Link]()
Returns a view of dictionary keys.
print([Link]()) # dict_keys(['a', 'b'])
[Link]()
Returns a view of dictionary values.
print([Link]()) # dict_values([1, 2])
[Link](key)
Removes the key and returns its value.
[Link] nloads/python_project.html 4/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
val = [Link]('b') # val = 2, d = {'a': 1}
[Link](other)
Updates dictionary with key-value pairs from another dict.
[Link]({'b': 3, 'c': 4})
# d = {'a': 1, 'b': 3, 'c': 4}
Tuple Methods (tuple) immutable
[Link](x)
Returns number of occurrences of x in the tuple.
t = (1, 2, 2, 3)
print([Link](2)) # 2
[Link](x[, start[, end]])
Returns first index of x, optionally searching between start and end.
print([Link](2)) # 1
print([Link](2, 2)) # 2
Set Methods (set) mutable
[Link](x)
Adds element x to the set.
[Link] nloads/python_project.html 5/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
s = {1, 2, 3}
[Link](4) # {1, 2, 3, 4}
[Link](x)
Removes element x from set. Raises KeyError if not present.
[Link](3) # {1, 2, 4}
[Link](x)
Removes x if present, doesn't raise error.
[Link](5) # No error
# s = {1, 2, 4}
[Link]()
Removes and returns arbitrary element.
item = [Link]() # Could be 1, 2, or 4
[Link](*others)
Returns union of sets as new set.
s1 = {1, 2}
s2 = {2, 3}
print([Link](s2)) # {1, 2, 3}
[Link] nloads/python_project.html 6/7
6/28/25, 10:32 PM Python Built-in Data Type Methods
[Link](*others)
Returns intersection of sets as new set.
print([Link](s2)) # {2}
Python Built-in Data Type Methods Reference Sheet
Generated on June 28, 2025
[Link] nloads/python_project.html 7/7