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

Python Functions Tables

Uploaded by

yohanmathew1906
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Python Functions Tables

Uploaded by

yohanmathew1906
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Functions Table

Functions That Return Values


Category Function/Method Description Example

Built-in Functions len() Returns the length len([1, 2, 3]) # 3


of an object

sum() Returns the sum of sum([1, 2, 3]) # 6


an iterable

max() / min() Returns the max([1, 2, 3]) # 3


maximum/minimu
m element of an
iterable

abs() Returns the abs(-5) # 5


absolute value of a
number

round() Returns a rounded round(5.678, 2) #


value 5.68

String Methods str.upper() Returns an "hello".upper() #


uppercase version "HELLO"
of the string

str.replace() Returns a string "hello


with specified world".replace("wor
values replaced ld", "Python") #
"hello Python"

str.split() Splits a string into a "a,b,c".split(',') #


list ['a', 'b', 'c']

str.join() Joins elements of an ",".join(["a", "b",


iterable into a string "c"]) # "a,b,c"

List Methods list.index() Returns the index of [10, 20,


the first occurrence 30].index(20) # 1
of a specified value
list.count() Returns the number [1, 2, 2, 3].count(2)
of times a specified #2
element appears

sorted() Returns a new sorted([3, 1, 2]) #


sorted list [1, 2, 3]

Math Functions math.sqrt() Returns the square math.sqrt(16) # 4.0


root of a number

math.pow() Returns a number math.pow(2, 3) #


raised to a power 8.0

math.sin(), etc. Trigonometric math.sin(math.pi/2)


functions that # 1.0
return values

Dictionary Methods dict.get() Returns the value {"key":


for a specified key "value"}.get("key")
# "value"

dict.keys() Returns a view of {"a": 1}.keys() #


the dictionary's keys dict_keys(['a'])

File Methods file.read() Returns the content content = file.read()


of a file

file.readline() Reads and returns line = file.readline()


one line

Functions That Do Not Return Values (Mutator Functions)


Category Function/Method Description Example

List Methods list.append() Adds an element to mylist.append(4)


the end of the list,
modifying it in place

list.extend() Extends the list by mylist.extend([5, 6])


appending elements
from an iterable

list.insert() Inserts an element mylist.insert(1, 'a')


at a specified
position
list.remove() Removes the first mylist.remove(2)
occurrence of a
specified value

list.sort() Sorts the list in mylist.sort()


place

list.reverse() Reverses the mylist.reverse()


elements of the list
in place

list.pop() Removes and element =


returns the last (or mylist.pop()
specified) element

Dictionary Methods dict.update() Updates the mydict.update({'ne


dictionary with key- w_key': 'value'})
value pairs

dict.pop() Removes and value =


returns the specified mydict.pop('key')
key-value pair

You might also like