Control Structures Flashcards

1
Q

Boolean

A

Binary variable, True or False

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

==

A

Creates boolean variable
ex: print(2==3) –> False

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

!=

A

Not equal operator
ex: print(1 != 1) –> False

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

> ,<

A

Determine if one float/integer is greater than or less than the other
ex: print(7 > 5) –>
True
print(10 < 10) –>
False

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

> =,<=

A

Determine if one float/integer is greater or equal to than or less than or equal to the other
ex: print(7 >= 5) –>
True
print(10 <= 10) –>
True

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

Lexicographically

A

How strings are compared, a=1 e=5, etc.
ex: print(“Annie” > “Andy”) –> True

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

if

A

Runs code if a certain condition holds True. Statement within are indented
ex: if 10 > 5:
print(“10 greater than 5”)

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

Can if statements be nested?

A

True
ex: num = 12
if num > 5:
print(“Bigger than 5”)
if num <=47:
print(“Between 5 and 47”) –>
Bigger than 5
Between 5 and 47

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

else

A

Runs code when the if statement is False
ex:
x = 4
if x == 5:
print(“Yes”)
else:
print(“No”)

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

elif

A

else if, used to chain else if statements
ex:
if num == 1:
print(“One”)
elif num == 2:
print(“Two”)
else:
print(“Something else”)

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

and

A

Evaluates True only if both statements are true
ex: print(1 == 1 and 2 == 2) –> True
print(1 == 1 and 2 == 3) –> False

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

or

A

Evaluates True if one or both statements are true, only evaluated False if both statements are false
ex:print(1 == 1 or 2 == 2) –> True
print(1 == 1 or 2 == 3) –> True

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

Not

A

Inverts argument
ex: print(not 1==1) –> False

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

== comes before and/or in order of operations

A

True

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

[]

A

Creates list
ex: words = [“Hello” , “World” , “!”]

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

What number is used to index the first number in a list?

A

0
ex: print(words[0])

17
Q

All items need to be the same type in a list

A

False
ex: things = [“string”, 0, [1, 2, number], 4.56]
#note how list contains strings, integers, floats, lists, and variables!

18
Q

Strings can be indexed like lists

A

True
ex: str = “Hello world!”
print(str[6]) –>
w
#spaces, ‘ ‘, count as a list item

19
Q

You cannot change specific items in lists

A

False
nums = [7, 7, 7, 7, 7]
nums[2] = 5
print(nums) –>
[7, 7, 5, 7, 7]

20
Q

in

A

Operator to determine if an item appears in a list
ex: print(“spam” in words) –>
True

21
Q

‘not’ in ‘in’ operator

A

To check if an item is not in a list
ex:
print(not 4 in nums)
print(4 not in nums)
#note multiple ways

22
Q

.append

A

Method that adds an item to the end of an existing list
ex:
nums = [1, 2, 3]
nums.append(4)
print(nums) –>
[1, 2, 3, 4]

23
Q

len()

A

Function that give number of items in list
ex:
nums = [1, 3, 5, 2, 4]
print(len(nums)) –>
5
#starts at 1, not 0

24
Q

.insert

A

Method that allows you to insert a new item anywhere in a list
ex:
words = [“Python”, “fun”]
words.insert(1, “is”)
print(words)

25
Q

.index

A

Method that finds first occurrence of item in list and returns index
ex:
list= [4 ,1 ,2 ,4]
list.index(1)–>
0

26
Q

max()

A

Returns list item with maximum value

27
Q

min()

A

Returns list item with minimum value

28
Q

.count

A

Method that returns a count of how many times an item occurs in a list

29
Q

.remove

A

Method that removes an object from a list

30
Q

.reverse

A

Method that reverses items in a list