Chapter 4 - For loops, Strings, and Tuples Flashcards

1
Q

an ordered list of things

A

a sequence

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

All sequences are made up of …..

A

elements

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

a sequence in which each element is one character

A

a string

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

(start, stop, step)

A

range(), the end point is not included (if it’s 50, 49 is the last number included)

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

find message length with…

a sequence’s length is equal to the number of elements it has.

A

len()

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

differences between elements and characters

A

a space is an element but not a character

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

going through a sequence one character at a time

A

sequential access

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

direct access

A

random access

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

you can specify a position in a sequence and get the element at that position

A

indexing

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

[-1] negative index number

A

last character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
high = len(word)
low = -len(word)

What index positions will this produce if word = “index”
position = random.randrange(low, high)

A

-5, -4, -3, -2, -1, 0, 1, 2, 3, 4
In other words: it will produce a random number from and including the low end point, up to, but NOT including the high end point.

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

the inability of strings to be changed

A

string immutability

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

A variable written in ALL CAPS by convention

  • more readible
  • used for variable meant to be unchaning
A

constant

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

a section of elements (part of a sequence)

A

a slice

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

start = None

A

placeholder, evaluates to False

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

slicing shorthand

A

word[:]

17
Q

type of sequence, unlike a string (which can only contain characters), it can contain elements of any type
it’s elements don’t have to be of the same type
whatever you assign to a variable, you can group together and store in a …..

A

tuple

18
Q

Can a tuple be treated as a condition

A

Yes

19
Q

Is an empty tuple treated as True or False?

A

False

20
Q

*Some programming languages offer structures similar to tuples (arrays; vectors). However, those languages usually restrict….

A

the elements of the sequences to just one type

21
Q

what does len() return when used on a tuple

A

the number of tuple elements

22
Q

Tuples: mutable or immutable?

A

immutable

23
Q

What happens during concatenation of tuples

A
The original tuple is not modified, because it is immutable. Instead, an augmented assignment operator can create a brand-new tuple with the elements from the previous tuples and assign that to (the name of the original variable [ tuple])
e. g. 
me = ("brain", "brawn")
you = ("skills", "pills")
me += you
>>>print(me)
('brain', 'brawn', 'skills', 'pills')
24
Q

message = “something”

print message backwards

A

print(message[::-1])