learn-ch4-objects Flashcards
what is the syntax for creating a list of integers?
l = [1,2,3]
Can you nest a list within a list?
yes
There are two different ways to create a dictionary with name, value. What are they?
d = {'name': 4} d = dict(name=4}
name 3 sequence types
lists, tuples, strings
what is the built-in function to return the length of a sequence?
len()
for pyhthon sequence types, what is the syntax to access the first element?
str[0] . it’s the braces and the offset. The offset starts at 0.
how to index backwards i.e. from right to left
use negative numbers str[-1]
what is the syntax for taking a slice of a string?
s = str[1:4]
what is the syntax for concatenation of sequences?
use the + between two sequences
In Python, are strings immutable?
yes
Are sequences immutable?
yes
If sequences are immutable, how can one concatenate two sequences?
They are combined into a new sequence
what function can be used to return all methods for a sequence?
dir(list3)
what function will bring up Pydoc for a type or method
help(type) or help(method)
how do you create a int literal in hexadecimal?
0xA . this is 10