Midterm review Flashcards

Zoom!! (55 cards)

1
Q

Variables

A

a bucket to store information in

ex) camelCase or snake_case

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

Integers

A

int

3 or -1 or 0 or 2001

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

Real Numbers

A

float

3.14 or 0.094 or -12.0

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

Character Strings

A

str

“Hi” “ “ “a” “44”

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

Boolean

A

bool

True or False

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

What is this? 3 != 3

A

boolean bc it’s a comparison

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

What is this? “Exam, Day, Soon”

A

string

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

What is this? 5.9

A

float

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

What is this? 2

A

integer

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

What is this? 5.9 - 3

A

float

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

What is this? 9 // 1

A

integer ( just 9 divided by 1)

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

What is this? 5.9 x 3

A

float

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

Concatenation

A
  • fancy name for string
  • has “ “ or ‘ ‘
  • concatenate by +
    • like gluing strings
      together (no spaces)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a method?

A
  • function or command
  • “called” with parenthesis
  • to access method, use dot.operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two parts of a string?

A

it’s data and it’s methods

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

s = “panang Curry”
method = upper()
print(s.upper())
output?

A

PANANG CURRY

uppercase version of string

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

s = “panang Curry”
method = lower()
print(s.lower())
output?

A

panang curry

lowercase version of string

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

s = “panang Curry”
method = swapcase()
print(s.swapcase())
output?

A

PANANG cURRY

case of each letter is switched

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

s = “panang Curry”
method = capitalize()
print(s.capitalize())
output?

A

Panang curry

1st letter capitalized and the rest are lowercase

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

s = “panang Curry”
method = title()
print(s.title())
output?

A

Panang Curry

first letter of each word is caps and rest is lowercase

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

How do you display:

She said “You need escape characters”
Which are: \important\

A

print(“She said "You need escape characters"” \nWhich are: \important\”

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

Which escape character lets you use double quotes in a string?

A

"

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

Which escape character lets you move to a new line?

24
Q

Which escape character allows you to include backslash in output?

25
Which escape characters allow for indents in strings?
\t
26
User input
- store input IN VARIABLE - ALWAYS returns a string ex) num = input("Enter a number: ") # num is string input("Enter a number: ") # useless
27
Branching
- CONDITION that evaluates whether a boolean is true or false - mutually exclusive - only ONE statement will run - multiple ifs = each if statement can potentially run depending on statement
28
if CONDITION
- # do something - only need if statement, doesn't need elif or else
29
elif CONDITION
- # do something - NEEDS if statement
30
else:
- # do something - NEEDS if statement
31
= vs ==
= used for assigning var to new value == used in your condition for comparison in if statements and while loops-- evaluates to true false ex) var = 3 print(3==3) TRUE
32
What's the error in this branching example? name = input("What's your name") if name == "Kyle" or "Beth": print("Please come in")
name = input("What's your name: ") everything has an associated truth value e.g. non-empty string = True non-zero number = True non-empty list = True so "Beth" evaluates to True always
33
Tracing if-statements x = 10 if x > 3 and x % 2 == 0: print("Success") else: print("Fail") 1) What will get printed? 2) What values of x will print "Success"?
1) print("Success") 2) x = 10
33
While loop
- Repeat code without writing repeated cote - Great for when you r loop should break: "I wan to loop until the user inputs'q'" - while userinput !='q'
34
For Loop
- for each loop - for char in "abcdefghijklmno" - Range loop - for i in range(start, stop, step) - for num in range(1) - for num in range(0,10) - for num in range(0,10,1)
35
List and strings are SEQUENCES
- accessing individual elements - indices start at 0 - string example - name= "jenny" - list example - name= ["jenny", "bob", "tina"]
35
List
- a collection of items - create a new list using list() or [ ] - are mutable
36
someList.append(value)
adds value to end of a list
37
someList.remove9vale)
Removes the first occurrence of value from the list
38
List slicing
- used for getting a subset of a list - list slicing returns another list - specify range of indices - someList[start:end]
39
items = ["shirt", "shoes , "pants", "hat", "socks", "tank top"] print(items[2:5]) What gets printed? *hint-- first item of a list always starts with the number 0
hat socks
40
split( ) and join ()
- split turns a string into a list - join turns a list into a string charList = excelRow.split(",") newString = "."join(someList)
41
1 items = ["shirt
41
42
43
44
44
45
46
47
48
49
50
51