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

Kilgrave Python Functions

This document provides a cheat sheet summarizing common Python functions for math, sets, strings, lists, and file handling. It lists functions like ceil(), copysign(), factorial(), and others for math operations. For sets it covers functions like add(), update(), remove(), and more. String functions include count(), find(), capitalize(), and others. List functions include append(), extend(), remove(), pop(), and more. File handling functions include open() to open a file object.

Uploaded by

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

Kilgrave Python Functions

This document provides a cheat sheet summarizing common Python functions for math, sets, strings, lists, and file handling. It lists functions like ceil(), copysign(), factorial(), and others for math operations. For sets it covers functions like add(), update(), remove(), and more. String functions include count(), find(), capitalize(), and others. List functions include append(), extend(), remove(), pop(), and more. File handling functions include open() to open a file object.

Uploaded by

steve noboD
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Functions Cheat Sheet

by atinfosec (KilGrave) via cheatography.com/69386/cs/17507/

Math Module Functions Math Module Functions (cont)

ceil(x) Returns the smallest integer greater than or equal to x e mathem​atical constant e (2.718​28...)
copysi​‐ Returns x with the sign of y * import math and use math.f​un()
gn(x, y)

fabs(x) Returns the absolute value of x Sets Functions

factor​ial(x) Returns the factorial of x S.add(e) Adds the element e to the set S
floor(x) Returns the largest integer less than or equal to x S1.upd​ate(S2) Adds the items specified in the set S2 to the set S1
fmod(x, y) Returns the remainder when x is divided by y S.remo​ve(e) Remove the element e from the set S
isfini​te(x) Returns True if x is neither an infinity nor a NaN (Not a S.pop() Removes any element from the set S
Number) S.clear() Remove all element from the set S
isinf(x) Returns True if x is a positive or negative infinity S.copy() Creates a copy of the set S
isnan(x) Returns True if x is a NaN S1.uni​on(S2) Returns a set containing elements from both S1
ldexp(x, i) Returns x (2*i) and S2
modf(x) Returns the fractional and integer parts of x S1.int​ers​ect​‐ Returns a set containing elements common in set
exp(x) Returns e**x ion(S2) S1 and S2

expm1(x) Returns e**x – 1 S1.dif​fer​enc​‐ Returns a set containing elements in set S1 but not
e(S2) in S2
log(x[, Returns the logarithm of x to the base (defaults to e)
base]) S1.sym​met​ric​‐ Returns a set containing elements which are in one
_di​ffe​ren​‐ of the either sets S1 and S2, but not in both
log2(x) Returns the base-2 logarithm of x
ce(S2)
log10(x) Returns the base-10 logarithm of x
pow(x, y) Returns x raised to the power y String Functions
sqrt(x) Returns the square root of x S.coun​‐ Counts the number of times string str occurs in string S
acos(x) Returns the arc cosine of x t(str)
asin(x) Returns the arc sine of x S.find​‐ Returns index of first occurrence of string str in string S,
atan(x) Returns the arc tangent of x (str) and -1 if str is not present int string S

atan2(y, x) Returns atan(y / x) S.rfin​‐ Returns index of last occurrence of string str in string S,
d(str) and -1 if str is not present in string S
cos(x) Returns the cosine of x
S.capi​‐ Returns a string that has first letter of the string S in
hypot(x, y) Returns the Euclidean norm, sqrt(xx + yy)
tal​ize() uppercase and rest of the characters in lowercase
sin(x) Returns the sine of x
S.title() Returns a string that has first letter of every word in the
tan(x) Returns the tangent of x
string S in uppercase and rest of the characters in
degrees(x) Converts angle x from radians to degrees lowercase
radians(x) Converts angle x from degrees to radians S.lower() Returns a string that has all uppercase characters in
gamma(x) Returns the Gamma function at x string S converted into lowercase characters

lgamma(x) Returns the natural logarithm of the absolute value of


the Gamma function at x
pi Mathem​atical constant, the ratio of circum​ference of a
circle to it's diameter (3.141​59...)

By atinfosec (KilGrave) Published 18th October, 2018. Sponsored by Readable.com


cheatography.com/kilgrave/ Last updated 19th October, 2018. Measure your website readability!
Page 1 of 2. https://readable.com
Python Functions Cheat Sheet
by atinfosec (KilGrave) via cheatography.com/69386/cs/17507/

String Functions (cont) String Functions (cont)

S.upper() Returns a string that has all lower characters in string S S.isdi​‐ Returns True if all characters in string S comprise of
converted into uppercase characters git() digits only, else False
S.swap​‐ Returns a string that has all lowercase characters in S.isal​‐ Returns True if all characters in string S comprise of
case() string S converted into uppercase characters and vice num() alphabets and digits only, else False
versa S.star​‐ Returns True if string S starts with string str​,else False
S.isup​‐ Returns True if all alphabets in string S are in upperc​‐ tsw​ith​‐
per() ase​,else False (str)
S.islo​‐ Returns True if all alphabets in string S are in lowerc​‐ S.ends​‐ Returns True if string S ends with string str​,else False
wer() ase​,else False wit​h(str)
S.isti​tle() Returns True if string S is in titlecase S.enco​‐ Returns S in encoded format according to the given

S.repl​‐ Returns a string that has every occurrence of string str1 de(str) encoding scheme

ace​(st​‐ in S replaced by with the occurrence of string str2 S.deco​‐ Returns the decoded string S according to the given
r1,​str2) de(str) encoding scheme
S.strip() Returns a string that has whites​paces in S removed from
start and end List

S.lstrip() Returns a string that has whites​paces in S removed from L.appe​‐ Adds the element e to the end of the list L
start nd(e)

S.rstrip() Returns a string that has whites​paces in S removed from L.exte​‐ Adds the items specified in the list L2 at the end of the
end nd(L2) list L

S.spli​t(d​‐ Returns a list formed by splitting the string S into various L.remo​‐ Remove the element e from the list L
eli​meter) substring. The delimeter is used to mark the split points ve(e)

S.part​iti​‐ Partitions the string S into two parts base on deli​meter L.pop(i) Removes the element specified at index i from the list
on(​del​‐ and returns a tuple comprising of string before deli​meter L*
imeter) L.count(e) Returns count of occurrence of element e in list L
S.join​(se​‐ Returns a string comprising of elements of the sequence L.index(e) Returns index of element e from list L
quence) separated by delimeter S
L.inse​rt(i,e) Returns element e at the index i in list L
S.issp​‐ Returns True if all characters in string S comprise of
L.sort() Sorts the elements of the list L
ace() whitespace characters only,i.e. ' ', '\n', '\t' else False
L.reve​rse() Reverses the order elements in list L
S.isal​‐ Returns True if all characters in string S comprise of
pha() alphabets only, else False
File Handling

open(f​ile​nam​e,mode) Open a file and store it as an object


file.c​lose() Close a file which is opened
file.r​ead() Read whole data from file
file.r​ead​line() Read a line from file
file.r​ead​lines() Read all the lines in a list from file
file.w​rit​e('​data') Write data in a file

* Mode can be 'r', 'w' and 'a'

By atinfosec (KilGrave) Published 18th October, 2018. Sponsored by Readable.com


cheatography.com/kilgrave/ Last updated 19th October, 2018. Measure your website readability!
Page 2 of 2. https://readable.com

You might also like