Values and Variable pt.2 Flashcards
What is a blank character?
An empty space
What is the result of 23%3?
2
What is the result of the following?
»> s=”Banana”
»>s[0:0:2]
> > > s=”Banana”
s[0:0:2]
“Bnn”
Define list
Sequence of values (any type of values)
Define elements or items
Values in a list
Define nested
A list within a list
What is an empty list?
A list that contains no items or elements
An example of an augmented assignment statement
FinalG += x
FinalG= FinalG+x
Are the following the same thing?
C = C+B
C += B
Yes. += is an augmented assignment statement
Define immutable
Unchangeable
Define class
A mechanism that allows us to create our own type of objects (variables)
What does the Syntax for method look like?
(<variable>)(<dot>)(<method>)(<argument>)</argument></method></dot></variable>
Are list mutable or immutable?
Mutable
An example of In Operator
> > > cheese=[“Cheddar”, “nacho”]
“nacho” in cheese
True
What will happen to the following and what is this function called?
»> cheese=[“Cheddar”, “nacho”]
»>”hi” in cheese
> > > cheese=[“Cheddar”, “nacho”]
“hi” in cheese
False
The In Operator
Example of a list
> > > a=[1,2]
Example of a list Operator
>>>a=[1,2] >>>b =[3,5] >>>c= a+b >>>c [1,2,3,5]
What will happen to the following and what is it called?
> > > t=[“a”, “b”, “c”, “d”]
t[1:3]
> > > t=[“a”, “b”, “c”, “d”]
t[1:3]
[“b”, “c”]
List slicing
What is this method called and what will happen as a result?
> > > t=[“a”,”b”]
t.append(“c”)
t
> > > t=[“a”,”b”]
t.append(“c”)
t
[“a”,”b”,”c”]
This method is called appending which adds a new element to the list
What is this method called and what will happen as a result?
> > > t1=[“a”,”b”]
t2=[“c”,”d”]
t1.extend(t2)
t1
>>>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.
What is this method called and what will happen as a result?
> > > t=[“a”,”b”,”c”]
x=t.pop(1)
t
> > > x
>>>t=["a","b","c"] >>>x=t.pop(1) >>>t ["a","c"] >>>x ["b"]
This method is called popping.
What is this method called and what will happen as a result?
> > > t=[“a”,”b”,”c”]
del t[1]
t
> > > t=[“a”,”b”,”c”]
del t[1]
t
[“a”,”c”]
Delete method
What is this method called and what will happen as a result?
> > > t=[“a”,”b”,”c”]
t.remove(“b”)
t
> > > t=[“a”,”b”,”c”]
t.remove(“b”)
t
[“a”,”c”]
What does the following do and what is its purpose?
> > > s=”ham”
t=list(s)
t
> > > s=”ham”
t=list(s)
t
[“h”,”a”,”m”]
To split the string into list of characters
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”]
Define delimiter
Special character/symbol to split sentence/strings. Also used to join.
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"]
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"
What is the result of this?
> > > s=”Banana”
s[0:0:2]
> > > s=”Banana”
s[0:0:2]
“Bnn”
What is the purpose of conditioned statement?
It gives us the ability to check the conditions and change the behaviour of the program
Define compound statement
A header followed by an indented body
Define branches
Alternative execution