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?

A

S * 8

25
Q

describe the meaning of + for numbers and strings

A

for numbers it means addition.

for strings it means concatenation.

26
Q

polymorphism in pythons means what?

A

the meaning of the operation depends on the objects being operated on.

27
Q

Every string operation is defined to produce a new string as its result, because every string is _______ in python.

A

immutable.

28
Q

what does immutable mean?

A

something cannot be changed in place after it has been created.

29
Q

What core types of objects are immutable?

A
  • numbers , strings , and tuples.
30
Q

immutability can be used so that you can guarantee that an object will remain _________throughout your program.

A

constant.

31
Q

descibe a method , w.r.t. a string.

A

functions attached to the object, which are triggered with a call expression.

32
Q

String methods are the _____ ______ of ___________n tools in python.

A

first line, test-processing.

33
Q

if S=”Spam”. what does S.find (‘pa’) return? , why?, and what happens to the original string?

A

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
Q

if S=”Spam”. what does S.replace(‘pa’, ‘XYZ’ ) return? and why?

A

“SXYZm”

35
Q

If I have a String line = ‘ aaa,bbb,ccc,dd’ what does the code line.split(‘,’) return?

A

[ ‘aaa’ , ‘bbb’, ‘ccc’ , ‘dd’ ].

36
Q

If I have a String line = ‘ aaa,bbb,ccc,dd’ what does the code line.upper() return?

A

‘AAA,BBB,CCC,DD’.

37
Q

string have an advanced substitution operation known as _________?

A

formatting.

38
Q

if i have the following : ‘%s , eggs , and %s’ % (‘spam’ , ‘SPAM’) what will be returned?

A

‘spam , eggs, and SPAM’

39
Q

if i have the following : ‘{1}, eggs , and {0}, {2}’ .format(‘spam’ , ‘SPAM’, ‘Spam’) what will be returned?

A

‘SPAM, eggs and spam Spam

40
Q

If i have the string S=’Spam’. what built in function will return the attributes of the object S=’Spam’.

A

dir() function.

  • example:&raquo_space;> dir(S)
  • because methods are function attributes.
41
Q

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?

A
  • \n for end of line
    -\t for tab.
    -A
    B C
42
Q

Lists are also __________?

A

Sequences.

43
Q

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.

A

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
Q

lists are _______ order ___________ of __________ typed objects. they also have ___ fixed ______ .

A

positionally , collections, arbitrarily, no, size.

45
Q

Becuase list are sequences , list support all the _________ ___________ so far discussed.

A

sequence operations

46
Q

if L = [ 123, ‘spam’ , 1.23 ] what does the command len(L) return?

A

3

47
Q

if L = [123 , ‘spam’, 1.23] what does L[0} return?

A

123

48
Q

do list have a type constraint?

A
no 
# which means a list can have strings , integars, floating point numbers .
49
Q

if I have the list L = [123 , ‘spam’, 1.23], how would I add ‘NI’ to the list ?

A

L.append(‘NI’)

50
Q

if I have the list L = [123 , ‘spam’, 1.23] what does L.append(‘NI’) return?

A

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

if L = [123 , ‘spam’, 1.23] what does L.pop(2) do?

A
it returns >>> 1.23 
# shrinking: delete an item based on the given offset.