Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
17 Cards in this Set
- Front
- Back
Help function |
help(function_name) |
|
Get and change working directory |
import os os.getcwd() os.chdir("dir_path") |
|
Check object class |
type(object) |
|
How to define a tuple |
Y=(1,"a",2,"b") Define with parenthesis. Once initialized, triples can't be changed. Tuples can contain mixed object types. |
|
How to define a list |
X=[1,"a",2,"b"] Define with square brackets. Lists can be edited. Lists can mix object types. |
|
How to add an object to the end of a list |
X.append("c") Appending CHANGES the original list. It does NOT return a copy. Lists can be appended to lists, but the entire sub-list will occupy one list element. |
|
How to sunset a list |
X[0:3] Subset with square brackets Indexing begins at 0 Second index is EXCLUSIVE, not inclusive. Can index from end of list with negative indexes. |
|
Concatenate lists |
[1,2]+[3,4]=[1,2,3,4] |
|
Check if a value is in a list |
1 in [1,2,3,4] |
|
How to split a string |
S.split(" ") Splits a string into a list of strings, separating at every space. |
|
How to define a dictionary |
D={"key":"value"} |
|
Retrieve a value from a dictionary |
Single value: D["key"] All values: D.values() |
|
For loop syntax |
for i in x: print(i) |
|
While loop syntax |
i=0 while(i!=len(x)): print(x[i]) i=i+1 |
|
If-then-else statement syntax |
if x[0]==1: print("yes") elif x[0]==2: print("maybe") else: print("no") |
|
Map function |
map(func, list1, list2) Returns a map object, which will apply func with elements from list1 and list2 as arguments. Must be queried individually. Does not return a list. |
|
Define a lambda |
lambda x: (x%2==0) |