Values and Variable pt.2 Flashcards

0
Q

What is a blank character?

A

An empty space

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

What is the result of 23%3?

A

2

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

What is the result of the following?
»> s=”Banana”
»>s[0:0:2]

A

> > > s=”Banana”
s[0:0:2]
“Bnn”

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

Define list

A

Sequence of values (any type of values)

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

Define elements or items

A

Values in a list

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

Define nested

A

A list within a list

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

What is an empty list?

A

A list that contains no items or elements

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

An example of an augmented assignment statement

A

FinalG += x

FinalG= FinalG+x

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

Are the following the same thing?

C = C+B
C += B

A

Yes. += is an augmented assignment statement

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

Define immutable

A

Unchangeable

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

Define class

A

A mechanism that allows us to create our own type of objects (variables)

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

What does the Syntax for method look like?

A

(<variable>)(<dot>)(<method>)(<argument>)</argument></method></dot></variable>

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

Are list mutable or immutable?

A

Mutable

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

An example of In Operator

A

> > > cheese=[“Cheddar”, “nacho”]
“nacho” in cheese
True

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

What will happen to the following and what is this function called?
»> cheese=[“Cheddar”, “nacho”]
»>”hi” in cheese

A

> > > cheese=[“Cheddar”, “nacho”]
“hi” in cheese
False

The In Operator

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

Example of a list

A

> > > a=[1,2]

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

Example of a list Operator

A
>>>a=[1,2]
>>>b =[3,5]
>>>c= a+b
>>>c
[1,2,3,5]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What will happen to the following and what is it called?

> > > t=[“a”, “b”, “c”, “d”]
t[1:3]

A

> > > t=[“a”, “b”, “c”, “d”]
t[1:3]
[“b”, “c”]

List slicing

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

What is this method called and what will happen as a result?

> > > t=[“a”,”b”]
t.append(“c”)
t

A

> > > t=[“a”,”b”]
t.append(“c”)
t
[“a”,”b”,”c”]

This method is called appending which adds a new element to the list

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

What is this method called and what will happen as a result?

> > > t1=[“a”,”b”]
t2=[“c”,”d”]
t1.extend(t2)
t1

A
>>>t1=["a","b"]
>>>t2=["c","d"]
>>>t1.extend(t2)
>>>t1
["a","b","c","d"]

This method is called extending which you take a list and combine it with another list.

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

What is this method called and what will happen as a result?

> > > t=[“a”,”b”,”c”]
x=t.pop(1)
t

> > > x

A
>>>t=["a","b","c"]
>>>x=t.pop(1)
>>>t
["a","c"]
>>>x
["b"]

This method is called popping.

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

What is this method called and what will happen as a result?

> > > t=[“a”,”b”,”c”]
del t[1]
t

A

> > > t=[“a”,”b”,”c”]
del t[1]
t
[“a”,”c”]

Delete method

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

What is this method called and what will happen as a result?

> > > t=[“a”,”b”,”c”]
t.remove(“b”)
t

A

> > > t=[“a”,”b”,”c”]
t.remove(“b”)
t
[“a”,”c”]

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

What does the following do and what is its purpose?

> > > s=”ham”
t=list(s)
t

A

> > > s=”ham”
t=list(s)
t
[“h”,”a”,”m”]

To split the string into list of characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
What does the following do and what is its purpose? >>>s= "love ham" >>>t=s.split() >>>t
>>>s= "love ham" >>>t=s.split() >>>t ["love","ham"]
25
Define delimiter
Special character/symbol to split sentence/strings. Also used to join.
26
What is this method called and what will happen as a result? >>>b="hi-hi-hi" >>>delimiter="-" >>>t=b.split(delimiter) >>>t
``` >>>b="hi-hi-hi" >>>delimiter="-" >>>t=b.split(delimiter) >>>t ["hi","hi","hi"] ```
27
What is this method called and what will happen as a result? >>>t=["I","love","ham"] >>>delimiter=" " >>>s= delimiter.join(t) >>>s
``` >>>t=["I","love","ham"] >>>delimiter=" " >>>s= delimiter.join(t) >>>s " I love ham" ```
28
What is the result of this? >>>s="Banana" >>>s[0:0:2]
>>>s="Banana" >>>s[0:0:2] "Bnn"
29
What is the purpose of conditioned statement?
It gives us the ability to check the conditions and change the behaviour of the program
30
Define compound statement
A header followed by an indented body
31
Define branches
Alternative execution
32
Example of alternative execution
If x % 2= 0 print("x is even") else: print("x is odd")
33
Example of nested conditions
``` If x==y: print("x and y are equal") elif: print("x is greater than y") else: print("x is not equal to y") ```
34
Define Boolean expression
Boolean expression is an expression that is either true or false
35
What does this Operator mean? --
Compare or equal
36
What happens if you type in type(True)
37
What happens if you type in type(False)?
38
What does this Operator mean? x!=y
X is not equal to y
39
What does this Operator mean? x>=y
X is greater or equal to y
40
What are the three logical Operator?
"And" "or" "not"
41
Define chained conditionals
Conditional statements that contain more than one "if" or "elif"
42
What are the results when doing Boolean expression with "and"?
True and True = True True and False= False False and True= False False and False= False
43
What are the results when doing Boolean expression with "not"?
Not true=False | Not False= true
44
What are the results when doing Boolean expression with "or"?
True or true= True True or False= True False or True= True False or False= false
45
Define short-circuit evaluation
Short-circuit evaluation is the semantics of Boolean expressions in which the second argument is executed or evaluated if the first argument does not determine the value of the expression.
46
What are the 6 truth values?
``` True 1 Numbers other than zero Nonempty list Nonempty strings Nonempty dictionaries ```
47
What are the 6 false values?
``` False 0 String "none" Empty strings Empty lists Empty dictionaries ```
48
An example of relational operator
!= | /=
49
Special rules
For "and" Operator, if left value is true, then right value is checked and returned. If left value is false, then it is returned. For "or" Operator if left value is true, then it is returned, otherwise if right value is false, right value is returned.
50
Fun fact
When Python functions and methods do not return any values, the value None is returned
51
What will happen to the following? >>> age=37 >>> age>4 and age== 7
>>> age=37 >>> age>4 and age==7 False
52
What will happen to the following? >>> age=8 >>>not(age==8)
>>> age=8 >>>not(age==8) False
53
What will happen to the following? >>> age=89 >>> age==89 or age < 10
>>> age=89 >>> age==89 or age < 10 True
54
What will happen to the following? | >>> 'a'==('a' or 'b')
>>> 'a'==('a' or 'b') True (Refer to special rules)
55
What will happen to the following? >>>'b'== ('j' or 'b')
>>>'b'==('j' or 'b') | False
56
What will happen to the following? | >>>'a'==('a' and'b')
>>>'a'==('a' and'b') | False
57
What will happen to the following? | >>>'b'=('a' and 'b')
>>>'b'=('a' and 'b') | True
58
Will the following produce an error? >>>newList=[1,2] >>>newList.insert(2,3)
No
59
What will the following produce? >>> newList=[1,2] >>> newList=newList.insert(2,3)
None
60
What will the following produce? >>>age=32 >>>age='34' and age<35
>>>age=32 >>>age='34' and age<35 Error!
61
What will the following produce? >>>age=34 >>>age>35 and age=='23'
>>>age=34 >>>age>35 and age=='23' False
62
What does the Syntax for "for" loop look like?
for (Iterating variable) in (sequence): | (Statement to be repeated)
63
Define iterative statement
Allows us to repeat our statement in our programs
64
Define temporary variable
A variable used to store an intermediate value in a complex calculation
65
Define dead code
Part of a program that can never run, often because it appears after a return statement
66
Define incremental development
A program development plan intended to avoid debugging by adding and testing only a small amount of code at a time
67
Define scaffolding
Code that is used during program development but it is not part of the final version
68
Define guardian
A program pattern that used a conditional statement to check for and handle circumstances that might cause an error
69
Define lexicographical order
It is order used to organize the word in a dictionary
70
Define traverse
To iterate through the items in a sequence, performing a similar operation on each
71
Define counter
A variable used to count something, usually initialized to zero, then incremented
72
Define iterate
To repeat
73
Define search
A pattern of traversal that stops when it finds what it is looking for
74
What will happen? >>>'ab'>'ac'
>>>'ab'>'ac' False a=a is the same but c is higher than b in terms of UNICODE
75
What is the Syntax for the built in function range()?
Range(start, stop, step)
76
What will happen? | >>>list(range(10))
>>>list(range(10)) | [0,1,2,3,4,5,6,7,8,9]
77
What will happen to the following? >>>x="47" >>>x.isdigit()
>>>x="47" >>>x.isdigit() True
78
What will happen to the following? >>>x=47 >>>x.isdigit()
>>>x=47 >>>x.isdigit() Error. Must be a string
79
What will happen to the following? >>>x="47.0" >>>x.isdigit()
>>>x="47.0" >>>x.isdigit() Error because of decimals
80
Define flag or sentinel
Conditions that stop while loops or infinite loop