Common operations
October 28, 2021
0.1 String operations
• upper() - returns a string in uppercase
• lower() - returns a string in lowercase
• len() - returns the length of a string
• count() - returns the number of occurrences of a string within another string
• replace() - returns a string with specific text replaced
• find() - return the first position where a substring is found, or -1 if it is not found
• strip() - returns a string with all leading and trailing whitespace removed
0.2 Sequence operations
• x in s - true if an item of s is equal to x, else false
• x not in s - false if an item of s is equal to x, else true
• s[i] - ith itom of s, origin 0
• s[i:j] - slice of s from i to j
• s[i:j:k] - slice of s from i to j with step k
0.3 Comparisons
• < - strictly less than
• <= - less than or equal
• > - strictly greater than
• >= - greater than or equal
• == - equal
• != - not equal
• is - object identity
• is not - negated object identity
0.4 Numeric operations
• x+y - sum of x and y
• x-y - difference of x and y
• x*y - product of x and y
• x/y - quotient of x and y
• x//y - floored quotient of x and y
• x%y - remainder of x/y
• int(x) - x converted to integer
• float(x) - x converted to floating point
• x**y - x to the power y
1
October 28, 2021
0.1 String operations
• upper() - returns a string in uppercase
• lower() - returns a string in lowercase
• len() - returns the length of a string
• count() - returns the number of occurrences of a string within another string
• replace() - returns a string with specific text replaced
• find() - return the first position where a substring is found, or -1 if it is not found
• strip() - returns a string with all leading and trailing whitespace removed
0.2 Sequence operations
• x in s - true if an item of s is equal to x, else false
• x not in s - false if an item of s is equal to x, else true
• s[i] - ith itom of s, origin 0
• s[i:j] - slice of s from i to j
• s[i:j:k] - slice of s from i to j with step k
0.3 Comparisons
• < - strictly less than
• <= - less than or equal
• > - strictly greater than
• >= - greater than or equal
• == - equal
• != - not equal
• is - object identity
• is not - negated object identity
0.4 Numeric operations
• x+y - sum of x and y
• x-y - difference of x and y
• x*y - product of x and y
• x/y - quotient of x and y
• x//y - floored quotient of x and y
• x%y - remainder of x/y
• int(x) - x converted to integer
• float(x) - x converted to floating point
• x**y - x to the power y
1