learn-ch4-objects Flashcards

1
Q

what is the syntax for creating a list of integers?

A

l = [1,2,3]

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

Can you nest a list within a list?

A

yes

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

There are two different ways to create a dictionary with name, value. What are they?

A
d = {'name': 4}
d = dict(name=4}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

name 3 sequence types

A

lists, tuples, strings

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

what is the built-in function to return the length of a sequence?

A

len()

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

for pyhthon sequence types, what is the syntax to access the first element?

A

str[0] . it’s the braces and the offset. The offset starts at 0.

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

how to index backwards i.e. from right to left

A

use negative numbers str[-1]

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

what is the syntax for taking a slice of a string?

A

s = str[1:4]

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

what is the syntax for concatenation of sequences?

A

use the + between two sequences

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

In Python, are strings immutable?

A

yes

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

Are sequences immutable?

A

yes

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

If sequences are immutable, how can one concatenate two sequences?

A

They are combined into a new sequence

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

what function can be used to return all methods for a sequence?

A

dir(list3)

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

what function will bring up Pydoc for a type or method

A

help(type) or help(method)

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

how do you create a int literal in hexadecimal?

A

0xA . this is 10

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

what is the use of the ‘’’ triple quotes?

A

string literal that is multi-line

17
Q

How do you use the raw string? when is this useful?

A

r’~/Documents/Projects/Python/main.py’ - disables escape