Deck 1 Flashcards

1
Q

#

A

Comment – anything after this does not get read by computer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

print()

A

Print function. Computer will “speak” the words inside this, as long as there are quotation marks around the words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

strings

A

Blocks of text. Must have either “double” or ‘single’ quotation marks around them. Must be consistent with either double or single all the way through.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

variable

A

Assigns string of data to this using equal sign. Data is stored for later use. Must use quotation marks for strings. this = “the string of data to be stored”
print(this) –outputs– the string of data to be stored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

variable rules

A

Can’t have spaces or symbols other than underscore (_). Cannot begin with number, although can have numbers in it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

reserved words a

A

and
as
assert

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

reserved words b

A

break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

reserved words c

A
class 
continue
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

reserved words d

A
def 
del
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

reserved words e

A

elif
else
except

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

reserved words f

A

finally
for
from

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

reserved words g

A

global

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

reserved words i

A

if
import
in
is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

reserved words l

A

lambda

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

reserved words n

A

nonlocal

not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

reserved words o

A

or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

reserved words p

A

pass

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

reserved words r

A

raise

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

reserved words t

A

try

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

reserved words w

A

while

with

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

reserved words y

A

yield

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

> > >

A

interactive chevron prompt. this prompt is the Python interpreter’s way of asking you, “What do you want me to do next?” Python is ready to have a conversation with you.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

quit()

A

the proper way to say “good-bye” to Python. enter at interactive chevron prompt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

script

A

python file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

.py

A

file extension for python scripts, what python files are saved as

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

$

A

operating system prompt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

numbers

A

numbers without quotation marks make them math-y and can be used in math operations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

+

A

adds stuff together, both numbers and words

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

-

A

subtracts stuff

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

*

A

multiplies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

/

A

divides

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

reserved words

A

we must use these words to mean the thing that python expects them to mean, so we cannot use them in variables or such

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

len()

A

function that tells you how many characters are in a string OR how many items are in a list

print(len(list))
print(len(string))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

integers

A

whole numbers (including negatives)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

float

A

numbers with decimals, or fractions, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

int()

A

converts a string to a number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

boolean

A

term for a value that is either True or False, or Yes or No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

True

A

equal to 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

False

A

equal to 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

boolean expression

A

a combination of booleans (and comparison operators) that evaluates to True or False, or Yes or No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

and

A

A boolean operator. An expression with ‘and’ evaluates to True if and only if both parts of the expression are True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

or

A

A boolean operator. True if either side of the expression is true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

not

A

Negates a boolean value and makes it the opposite of whatever it currently is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

if

A

If statements. They allow a python program to make decisions based on boolean expressions. The code following keyword if must be a boolean expression.
if boolean statement : (equates to true or false)
print(‘whatever’) executes “then statement” if true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

code is executed in an if statement

A

when the condition is True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

elif

A
chains multiple conditions together
if 
elif 
elif 
(only one value outputs, not all three as would happen if all were if)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

else

A

when if condition is false, else block will be executed
added at end of an if block

statement

if statement :
then statement (runs if true)
else :
then statement (runs if false)

final statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

list

A

contains values that are accessed by indexes [0, 1, 2, 3, 4] mix of numbers and words, words must be in quotes , commas between can be strings, integers, floats, etc.
var = [0, 1, 2, 3, 4] [ ] makes it a list

49
Q

index

A

first value is at index 0 indexes are list values [0, 1, 2, 3, 4]

50
Q

printing lists

A

print(listname) prints everything including parenthesis
phillies = [“aaron”, 27, “bryce”, 3, “jt”, 10]
print(phillies)
[“aaron”, 27, “bryce”, 3, “jt”, 10]
print index values to get individual entries
print(phillies[0])
aaron
print(phillies[1])
27

51
Q

append()

A

adds a value to a list
print(listname)
listname.append(‘new entry’)

52
Q

pop()

A
deletes a value from the list, will delete last one unless specified 
listname = ["a", "b", "c"]
listname.pop()
print(listname)
["a", "b"]

listname = [“a”, “b”, “c”]
listname.pop(0)
print(listname)
{“b”, “c”]

53
Q

in

A

tests whether list contains a value, will output True or False
listname = [“kiwi”, 4, “grape”, 5, “basket”]
print(“grape” in listname)
True
print(“apple” in listname)
False

54
Q

dictionary

A
a collection of key-value pairs, an associative array 
dictname = {
   "key": "value", 
   "entry": "definition", 
   "a": "b"
}
55
Q

printing a dictionary

A

print(dictname)

56
Q

key

A

first entry in a dictionary pair surrounded by quotes, followed by colon

57
Q

value

A

second entry in a dictionary pair surrounded by quotes, separated by comma

58
Q

accessing value of a key

A

x = dictname[“key”]

print(x)

59
Q

getting value of a key

A

x = dictname.get(“key”)

print(x)

60
Q

overwriting value in a dictionary

A

names = {“John” : “Doe”}
names[“John”] = “Smith”
print(names)

dictname = {“key” : “oldvalue”}
dictname[“key”] = “newvalue”
print(dictname)

61
Q

**

A

power

62
Q

%

A

remainder/modulo does the division, but gives the remainder instead of the quotient

63
Q

operator precedence rules

A
  1. Parentheses
  2. Exponents
  3. Multiplication, Division, and Remainder
  4. Addition and Subtraction
  5. Left to right
64
Q

float()

A

converts to floating point

65
Q

input()

A

a function that allows user input
input(prompt)
x = input(“Enter your name:”)
print(“Hello, “ + x)

66
Q

conditional statements

A

statement
if statement : (if + boolean statement)
then statement (must be indented by 4 spaces, will run if boolean statement if true; then statement is often print(‘whatever’))
if statement : (if + boolean statement)
then statement (must be indented by 4 spaces, will run if boolean statement if true)

final statement

67
Q

<=

A

less than or equal to

68
Q

==

A

equal to

69
Q

> =

A

greater than or equal to

70
Q

>

A

greater than

71
Q

!=

A

not equal

72
Q

indenting in conditional code

A

indenting is vital to run “then” statements, won’t run without them
4 spaces
can run multiple “then” statement off one “if” statement, as long as they are all indented will run until next non-indented statement
to stay in block of code, maintain/increase indent; to get out of block of code, decrease indent
see colon, indent

73
Q

…<=….

A

less than

74
Q

try

A

tries the code paired with except if no exception error, try code will run and except will be ignored if error, except code will run and try will be ignored
try:
code

75
Q

except

A

runs when exception error occurs in try code usually an error message comes after try: code
except:
code

76
Q

function

A

a block of organized, reusable code that is used to perform a single, related action

stores for later, like a variable that holds code

some stored code that we use. takes some input and produces an output

77
Q

defining a function

A
def funcname() : 
   indent- print('whatever')
   indent -print('this thing') 

conditions for function (indented things) will be executed whenever function is called

function ends when de-indented

78
Q

calling function

A

funcname()

will execute function conditions

79
Q

argument

A

information can be passed into functions (when called) as this

goes in parenthesis of function name

80
Q

type()

A

method returns class type of the argument(object) passed as parameter. this function is mostly used for debugging purposes

81
Q

parameter

A

variable listed inside the parentheses in the function definition

can use if elif else with variable indent 
def greet (lang) : 
indent   if lang == 'es' : 
indx2        print('Hola') 
ind    elif lang == 'fr' :
indx2      print('Bonjour') 
ind    else:
indx2        print('Hello')
82
Q

return

A

lets a function return a value

def my_function(x) : 
    return 5*x 

print(my_function(3))

15

83
Q

fruitful function

A

one that produces a return value

84
Q

multiple parameters/arguments

A

separate with commas

85
Q

for

A

loop used for iterating (repeating) over a sequence (that is either a list, a tuple, a dictionary, a set, or a string)

fruits = [“apple”, “strawberry”, “cherry”]
for x in fruits:
ind print(x)

86
Q

while

A

loop used for executing a set of statements as long as a condition is true

87
Q

in

A

python keyword used to:

a. check if value is present in a sequence (list, range, string, etc.)
b. used to iterate through a sequence in a for loop

88
Q

break

A

stops the loop, ends the current loop and jumps to the statement immediately following the loop

if x == “whatever” :
ind break

89
Q

continue

A

ends the current iteration and jumps to the top of the loop and starts the next iteration

if x == “whatever” :
ind continue

90
Q

i

A

variable for integer iteration

91
Q

counting in a loop

A

to count how many times we execute a loop, we introduce a counter variable that starts at 0 and we add one to it each time through the loop

count = 0 
print('Before', count) 
for thing in [n1, n2, n3, n4, n5] : 
ind count = count + 1 
ind print(count, thing) 
print ('After', count)
92
Q

summing in a loop

A

to add up a value we encounter in a loop, we introduce a sum variable that starts at 0 and we add the value to the sum each time through the loop

total = 0 
print ('Before', total) 
for thing in [n1, n2, n3, n4, n5] : 
ind    total = total + thing 
ind   print = (total, thing) 
print ('After', total)
93
Q

finding the average in a loop

A

an average just combines the counting and sum patterns and divides when the loop is done

count = 0 
sum = 0 
print ('Before', count, sum) 
for value in [n1, n2, n3, n4, n5] : 
ind count = count + 1 
ind sum = sum + value 
ind print (count, sum, value) 
print ('After', count, sum, sum / count)
94
Q

filtering in a loop

A

we use an if statement in the loop to catch/filter the values we are looking for

print('Before')
for value in [n1, n2, n3, n4, n5] : 
ind    if value > 20 : 
indent2        print 'Large number' ,value 
print ('After')
95
Q

search using a boolean variable

A

If we just want to search and know if a value was found, we use a variable that starts at False and is set to True as soon as we find what we are looking for

found = False 
print('Before', found) 
for value in [n1, n2, n3, n4, n5, n6] : 
ind    if value == n4 : 
indent2        found = True 
ind    print(found, value) 
print('After', found)
96
Q

None

A

absence of a value variable

97
Q

finding the smallest value

A

the first time through the loop smallest is None, so we take the first value to be the smallest

smallest = None 
print('Before') 
for value in [n1, n2, n3, n4, n5, n6] : 
ind    if smallest is None : 
indent2        smallest = value 
ind    elif value < smallest : 
indent2        smallest = value 
ind    print {smallest, value) 
print('After', smallest)
98
Q

is

A

operator that can be used in logical expressions
implies “is the same as”
similar to, but stronger than ==
returns True if both variables are the same object

99
Q

is not

A

also a logical operator

returns True if both variables are not the same object

100
Q

index operator

A

access each letter in a string with an index that starts at 0

in square brackets, pronounced ‘sub’

fruit = ‘banana’
letter = fruit[1]
print(letter)
a

banana
012345

101
Q

looping through strings (indeterminate)

A

using a while statement and an iteration variable, and the len function, we can construct a loop to look at each of the letters in a string individually

fruit = 'banana' 
index = 0
while index < len(fruit) : 
ind    letter = fruit[index] 
ind    print(index, letter) 
ind    index = index + 1
0 b
1  a 
2 n
3 a
4 n
5 a
102
Q

looping through string (determinate)

A

a definite loop using a for statement, the iteration variable is completely taken care by the for loop

fruit = 'banana' 
for letter in fruit : 
ind    print(letter) 
b
a
n
a
n
a
103
Q

looping and counting number of things

A

counting number of ‘a’s in banana -

word = 'banana' 
count = 0 
for letter in word : 
ind    if letter == 'a' : 
indent2       count = count + 1 
print (count)
104
Q

slicing strings

A

can look at any continuous section of a string using a colon operator
the second number is one beyond the end of the slice - “up to but not including”
if the second number is beyond the end of the string, it stops at the end
if we leave off first number the last number of the slice, it is assumed to be the beginning or end of the string respectively

>>> s = 'Monty Python' 
>>> print(s[0:4]) 
Mont 
>>> print(s[6:7])
p 
>>> print(s[6:20])
Python 

Monty Python
1234567891011

>>> s = 'Monty Python' 
>>> print(s[:2])
Mo 
>>> print(s[8:]) 
thon 
>>> print(s[:])
Monty Python
105
Q

string concatenation

A

applying + operator to strings, must add spaces in separately

a = ‘Hello’
b = a + ‘There”
print(b)

c = a + ‘ ‘ + ‘There’
print(c)

106
Q

in as a logical operator

A

the in keyword can also be used to check to see if one string is “in” another string
the in expression is a logical expression that returns True or False and can be used in an if statement

fruit = ‘banana’
‘n’ in fruit
True

‘m’ in fruit
False

‘nan’ in fruit
True

if ‘a’ in fruit:
ind print(‘Found it!’)
Found it!

107
Q

string comparison

A

uppercase letters are less than lowercase letters

if word == ‘banana’ :
print(‘All right, bananas.’)

if word < ‘banana’:
print(‘Your word,’ + word + ‘, comes before banana.’)
elif word > ‘banana’:
print(‘Your word,’ + word + ‘, comes after banana.’)
else:
print(‘All right, bananas.’)

108
Q

objects

A

variables that have capabilities that are grafted on or built into them
(strings are objects)

109
Q

method

A

function that belongs to/built into an object

110
Q

dir

A

lists methods available for an object

dir(object)

111
Q

string functions

A

functions built into strings
invoke them by appending the function to the string variable
functions do not modify original string, they return a new string that been altered

112
Q

string library

A

where the string functions are

113
Q

.lower()

A

makes string lowercase

> > > greet = ‘Hello Bob’
zap = greet.lower( )
print(zap)
hello bob

> > > print(‘Hi There’.lower())
hi there

114
Q

\n

A

new line

115
Q

\t

A

new tab

116
Q

'

A

puts single quote in a single-quoted string

117
Q

"

A

puts double quote in a double-quoted string

118
Q

:=

A
Walrus Operator (assignment expression operator) 
assigns variables in the middle of expressions