You are on page 1of 7

Python Programming – Exam Reference Sheet

String operators, functions, and methods

Usage Explanation

s.capitalize() returns a copy of s with first character capitalized

s.count(target) returns the number of occurrences of target in s

s.find(target) returns the index of the first occurrence of target in s

s.lower() returns lowercase copy of s

s.replace(old, new) returns copy of s with every occurrence of old replaced with new

s.split(sep) returns list of substrings of s, delimited by sep

s.strip() returns copy of s without leading and trailing whitespace

s.upper() returns uppercase copy of s

Page 1 of 7
List operators and functions

List methods

Page 2 of 7
Dictionary methods

Set methods

Page 3 of 7
Operator Precedence

One-way if statement syntax

Two-way if statement syntax

for loop syntax

while loop syntax

Page 4 of 7
function definition syntax

range() function

File Input/Output

Module random

random.randrange() : takes a pair of integers a and b, and returns some number between a and b-1

random.uniform(): takes two numbers a and b, and returns a float number x such that a <= x <= b

random.shuffle(): shuffles, or permutes, the objects in a sequence

random.choice(): allows us to choose an item from a container uniformly at random

random.sample(): takes an input the container and an integer k, and returns a list of k items in the
container

Page 5 of 7
Try-except syntax

Page 6 of 7
Page 7 of 7

You might also like