Chapter 4 Flashcards

1
Q

Programs are composed of what?

A

Modules.

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

Modules contain _____________?

A

Statements

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

Statements contain ______________?

A

Expressions

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

Expressions _______ and __________ objects

A

Create, and process

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

What are literals?

A

The expressions that generate objects

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

Everything that is processed in python is an ________?

A

Object.

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

Strings are used to store __________ __________ as well as __________ _________ of ________.

A

Textual information, arbitrary collection ,bytes

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

items in sequences are located and fetched using by their ______________?

A

relative position

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

Strictly speaking strings are sequences of _________ __________.

A

one character strings

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

if S = “Spam”, how would I return the length of hte string?

A

len(S).

len() is a built in functin in python.

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

With the string S=”Spam” what would the expression S[0} return?

A

“S”

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

Define what an index of a sequence is .

A

is a numbering system to identify the position of a charater in a sequence. always starts with 0.

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

Python variable never need to be _______ ahead of time?

A

declared.

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

Indexing is based on a ___________?

A

zero based position.

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

a variable is created when i _______ a _________ to it.

A

assign, value

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

positive indexes count from the ________. while negative indexes count from the _________.

A

front, back.

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

Slices are a way to extract an entire _________ from a string in a single step.

A

column

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

the form for slices X[ I :J] means what ?

A

give me everything from X from the offset I up to but not including offset J.

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

if S=”Spam” what does S[:3] return?

A

‘Spa’

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

if S=”Spam” . What does S[:] return?

A

‘Spam’

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

with respect to strings . how would i explain concatenation?

A

joining two strings to make one new string

22
Q

With respect to strings,how would i explain repetition?

A

making a new string by repeating another.

23
Q

if I had the string S=”Spam” and “xyz” how would i make them one string?

A

S+’xyz’

24
Q

how would i repeat the string S=”Spam” 8 times and make a new string?

25
describe the meaning of + for numbers and strings
for numbers it means addition. | for strings it means concatenation.
26
polymorphism in pythons means what?
the meaning of the operation depends on the objects being operated on.
27
Every string operation is defined to produce a new string as its result, because every string is _______ in python.
immutable.
28
what does immutable mean?
something cannot be changed in place after it has been created.
29
What core types of objects are immutable?
- numbers , strings , and tuples.
30
immutability can be used so that you can guarantee that an object will remain _________throughout your program.
constant.
31
descibe a method , w.r.t. a string.
functions attached to the object, which are triggered with a call expression.
32
String methods are the _____ ______ of ___________n tools in python.
first line, test-processing.
33
if S="Spam". what does S.find ('pa') return? , why?, and what happens to the original string?
1, ;because the method used is looking for the number of 'pa" found in the string "Spam" ;The original string remains unchanged because strings are immutable. we simply created a new string.
34
if S="Spam". what does S.replace('pa', 'XYZ' ) return? and why?
"SXYZm"
35
If I have a String line = ' aaa,bbb,ccc,dd' what does the code line.split(',') return?
[ 'aaa' , 'bbb', 'ccc' , 'dd' ].
36
If I have a String line = ' aaa,bbb,ccc,dd' what does the code line.upper() return?
'AAA,BBB,CCC,DD'.
37
string have an advanced substitution operation known as _________?
formatting.
38
if i have the following : '%s , eggs , and %s' % ('spam' , 'SPAM') what will be returned?
'spam , eggs, and SPAM'
39
if i have the following : '{1}, eggs , and {0}, {2}' .format('spam' , 'SPAM', 'Spam') what will be returned?
'SPAM, eggs and spam Spam
40
If i have the string S='Spam'. what built in function will return the attributes of the object S='Spam'.
dir() function. - example: >>> dir(S) - because methods are function attributes.
41
With the string S= 'A\nB\tC'. what does the \n and \t stand for? and and if I perform the print(S) action what does it return?
- \n for end of line -\t for tab. -A B C
42
Lists are also __________?
Sequences. ##Therefore all the operations that work with sequences also work on lists
43
Education: *The Python list object is the most general sequence provided by the language. *lists are positionally ordered collections of arbitrarily typed objects , They also have no fixed size.
Education: *Lists are mutable---unlike strings. lists can be changed in place by assignment to offsets as well as a variety of list method calls .
44
lists are _______ order ___________ of __________ typed objects. they also have ___ fixed ______ .
positionally , collections, arbitrarily, no, size.
45
Becuase list are sequences , list support all the _________ ___________ so far discussed.
sequence operations
46
if L = [ 123, 'spam' , 1.23 ] what does the command len(L) return?
3
47
if L = [123 , 'spam', 1.23] what does L[0} return?
123
48
do list have a type constraint?
``` no # which means a list can have strings , integars, floating point numbers . ```
49
if I have the list L = [123 , 'spam', 1.23], how would I add 'NI' to the list ?
L.append('NI')
50
if I have the list L = [123 , 'spam', 1.23] what does L.append('NI') return?
>>> [123 , 'spam', 1.23, 'NI'] Notice that the append method expands the list size and inserts the object at the end of the list.
51
if L = [123 , 'spam', 1.23] what does L.pop(2) do?
``` it returns >>> 1.23 # shrinking: delete an item based on the given offset. ```