Get 2 days of unlimited access
Study Guides (350,000)
US (200,000)
UC-Irvine (3,000)
I&C SCI (40)

I&C SCI 31 Study Guide - Final Guide: Docstring, Empty Set, Boolean Expression

Information and Computer Science
Course Code
I&C SCI 31
David Kay
Study Guide

This preview shows half of the first page. to view the full 2 pages of the document.
ICS 31 – Final Cheat Sheet
- len(str, or list)return the length of the argument
- print() print the argument
an additional argument could be included (sep=str, end=str)
sep: replaces the comma separator with the str instead of printing a space
end: ends each iteration of the print statement with the using the str
- help(function)returns the docstring for the argument
- range() returns the range of the argument
(two parameters: the beginning of the range and the end with zero indexing, one parameter: list, int)
- int() define argument as an int
- float() define argument as a float
- str() define argument as a str
- input() queries for users input (parameter: none, may contain a str to print)
- abs(int)return the absolute value of the int
- max(list)return the max value on the list
- min(list)return the min value on the list
- namedtuple() from collection import namedtuple
(parameters: ‘title’, ‘field field field …’)
- namedtuple._replace() replace the field of the namedtuple (parameters: field = item)
- list_of_namedtuple.sort(key=attrgetter(‘field’), reverse=True, or False)
From operator import attrgetter
returns the list of namedtuple based on a field that isn’t the first
- the key could also be a function that is defined to return the field to sort by
- list() defined by [ ], items are zero based indexed
- list.append() add an argument to the list (parameters: str, int, float, list, …, namedtuple)
- list.extend() add the items of the argument to the end of the list (parameters: list)
- list.sort() sort the list while affecting the original (parameters: key=field, reverse=True or False)
- sorted(list, key=function, reverse=True, or False)
sort the list without affecting the original
- list, or str.count() returns a count of the argument in the list, or str (parameter: int, str)
- str.split(str)returns a list with all the items in a str split at the argument
- str.strip(str)searches the str starting from both ends removing the argument until a new character gets in the way
- str.upper() returns a copy of the str converted to uppercase
- str.lower() returns a copy of the str converted to lowercase
- str.find(str)return the index position of the argument
- str.format(object, …, object)
include {:} in the str for each spot an argument is to be inserted
{:#d}, {:#s} – the number dictates the size of the field based on the number of characters
{#.#f} – the number after the decimal dictates how many decimal points to reserve out of the field size
if the specified field is smaller than the value, the whole value is inserted overwriting the specified size
s = strings, d = int, f = float
- str.makestrans(str, str)return a translation table in which the first str is made up of possible inputs and the second str the
corresponding outputs for the inputs with matching indexing
- str.translate(transtable)translates the str using the argument that is a translation table ^
- str.replace(str, str)return the string with replacing every occurrence of the first str of the argument with the second str
- str.join(list of str)return a string joining every item of the list with the str before the period
- str.title() returns the string with the first letter uppercase, and the rest lowercase
- open(‘filename.txt’, ‘mode’) opens a file
modes: r = read, w = overwrite, a = append to existing file
- the opened reads the file (parameter: none, or an int to print the first int characters)
- the opened file.readline() reads everything from the current position to the next \n
- the opened file.readlines() reads every line of the file into one list, including \n
- the opened file.write(str)writes the argument to the file
- the opened file.close() close the file that was open
You're Reading a Preview

Unlock to view full version