Values and Variable pt.2 Flashcards

You may prefer our related Brainscape-certified 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
Q

What does the following do and what is its purpose?

> > > s= “love ham”
t=s.split()
t

A

> > > s= “love ham”
t=s.split()
t
[“love”,”ham”]

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

Define delimiter

A

Special character/symbol to split sentence/strings. Also used to join.

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

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

> > > b=”hi-hi-hi”
delimiter=”-“
t=b.split(delimiter)
t

A
>>>b="hi-hi-hi"
>>>delimiter="-"
>>>t=b.split(delimiter)
>>>t
["hi","hi","hi"]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

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

> > > t=[“I”,”love”,”ham”]
delimiter=” “
s= delimiter.join(t)
s

A
>>>t=["I","love","ham"]
>>>delimiter=" "
>>>s= delimiter.join(t)
>>>s
" I love ham"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the result of this?

> > > 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
29
Q

What is the purpose of conditioned statement?

A

It gives us the ability to check the conditions and change the behaviour of the program

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

Define compound statement

A

A header followed by an indented body

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

Define branches

A

Alternative execution

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

Example of alternative execution

A

If x % 2= 0
print(“x is even”)
else:
print(“x is odd”)

33
Q

Example of nested conditions

A
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
Q

Define Boolean expression

A

Boolean expression is an expression that is either true or false

35
Q

What does this Operator mean? –

A

Compare or equal

36
Q

What happens if you type in type(True)

A

<class ‘bool’>

37
Q

What happens if you type in type(False)?

A

<class ‘bool’>

38
Q

What does this Operator mean? x!=y

A

X is not equal to y

39
Q

What does this Operator mean? x>=y

A

X is greater or equal to y

40
Q

What are the three logical Operator?

A

“And” “or” “not”

41
Q

Define chained conditionals

A

Conditional statements that contain more than one “if” or “elif”

42
Q

What are the results when doing Boolean expression with “and”?

A

True and True = True
True and False= False
False and True= False
False and False= False

43
Q

What are the results when doing Boolean expression with “not”?

A

Not true=False

Not False= true

44
Q

What are the results when doing Boolean expression with “or”?

A

True or true= True
True or False= True
False or True= True
False or False= false

45
Q

Define short-circuit evaluation

A

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
Q

What are the 6 truth values?

A
True 
1
Numbers other than zero
Nonempty list
Nonempty strings
Nonempty dictionaries
47
Q

What are the 6 false values?

A
False 
0
String "none"
Empty strings
Empty lists
Empty dictionaries
48
Q

An example of relational operator

A

!=

/=

49
Q

Special rules

A

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
Q

Fun fact

A

When Python functions and methods do not return any values, the value None is returned

51
Q

What will happen to the following?
»> age=37
»> age>4 and age== 7

A

> > > age=37
age>4 and age==7
False

52
Q

What will happen to the following?
»> age=8
»>not(age==8)

A

> > > age=8
not(age==8)
False

53
Q

What will happen to the following?
»> age=89
»> age==89 or age < 10

A

> > > age=89
age==89 or age < 10
True

54
Q

What will happen to the following?

|&raquo_space;> ‘a’==(‘a’ or ‘b’)

A

> > > ‘a’==(‘a’ or ‘b’)
True
(Refer to special rules)

55
Q

What will happen to the following?

> > > ‘b’== (‘j’ or ‘b’)

A

> > > ‘b’==(‘j’ or ‘b’)

False

56
Q

What will happen to the following?

|&raquo_space;>’a’==(‘a’ and’b’)

A

> > > ‘a’==(‘a’ and’b’)

False

57
Q

What will happen to the following?

|&raquo_space;>’b’=(‘a’ and ‘b’)

A

> > > ‘b’=(‘a’ and ‘b’)

True

58
Q

Will the following produce an error?

> > > newList=[1,2]
newList.insert(2,3)

A

No

59
Q

What will the following produce?

> > > newList=[1,2]
newList=newList.insert(2,3)

A

None

60
Q

What will the following produce?

> > > age=32
age=’34’ and age<35

A

> > > age=32
age=’34’ and age<35
Error!

61
Q

What will the following produce?

> > > age=34
age>35 and age==’23’

A

> > > age=34
age>35 and age==’23’
False

62
Q

What does the Syntax for “for” loop look like?

A

for (Iterating variable) in (sequence):

(Statement to be repeated)

63
Q

Define iterative statement

A

Allows us to repeat our statement in our programs

64
Q

Define temporary variable

A

A variable used to store an intermediate value in a complex calculation

65
Q

Define dead code

A

Part of a program that can never run, often because it appears after a return statement

66
Q

Define incremental development

A

A program development plan intended to avoid debugging by adding and testing only a small amount of code at a time

67
Q

Define scaffolding

A

Code that is used during program development but it is not part of the final version

68
Q

Define guardian

A

A program pattern that used a conditional statement to check for and handle circumstances that might cause an error

69
Q

Define lexicographical order

A

It is order used to organize the word in a dictionary

70
Q

Define traverse

A

To iterate through the items in a sequence, performing a similar operation on each

71
Q

Define counter

A

A variable used to count something, usually initialized to zero, then incremented

72
Q

Define iterate

A

To repeat

73
Q

Define search

A

A pattern of traversal that stops when it finds what it is looking for

74
Q

What will happen?

> > > ‘ab’>’ac’

A

> > > ‘ab’>’ac’
False
a=a is the same but c is higher than b in terms of UNICODE

75
Q

What is the Syntax for the built in function range()?

A

Range(start, stop, step)

76
Q

What will happen?

|&raquo_space;>list(range(10))

A

> > > list(range(10))

[0,1,2,3,4,5,6,7,8,9]

77
Q

What will happen to the following?

> > > x=”47”
x.isdigit()

A

> > > x=”47”
x.isdigit()
True

78
Q

What will happen to the following?

> > > x=47
x.isdigit()

A

> > > x=47
x.isdigit()
Error. Must be a string

79
Q

What will happen to the following?

> > > x=”47.0”
x.isdigit()

A

> > > x=”47.0”
x.isdigit()
Error because of decimals

80
Q

Define flag or sentinel

A

Conditions that stop while loops or infinite loop