python class

¡Supera tus tareas y exámenes ahora con Quizwiz!

lists and tuples are known as...

"collection variables," which store multiple values "sequence" variables, which go in a particular order.

a string (str) is what kind of data type

"immutable" - once created, they cannot be changedCannot assign to index / slice

In regex, which metacharacter matches the end of a string?

$

Which regex syntax will match only the first 3 digits in a string '93518'?

(r'(\d){3,5}?')

Which regex syntax requires that the match should start and end with a digit?

(r'^\d+$')

Comparison Operators

==, !=, >, <, >=, <=

Name a few ways that list values are similar to string values.

Both lists and strings can be passed to len(), have indexes and slices, be used in for loops, be concatenated or replicated, and be used with the in and not in operators

What is the difference between lists and tuples?

Lists are mutable; they can have values added, removed, or changed. Tuples are immutable; they cannot be changed at all. Also, tuples are written using parentheses, ( and ) , while lists use the square brackets, [ and ].

Which of these statements is true?

Python is a high level programming language. Python is an interpreted language. Python is an object-oriented language. All of the above.

Boolean Values

True/False

If numRegex = re.compile(r'\d+'), what will numRegex.sub('X', '12 books, 11 pens, four pencils, 3 notebooks') return?

X books, X pens, four pencils, X notebooks'

What escape character is used to display text on a new line?

\n

In regex, which metacharacter matches the start of a string?

carrot ^

If eggs contains a dictionary with the following items {'bread':1,'milk':2,'cream':4}, which code produces this output:(['bread', 'milk', 'cream'])

eggs.keys()

Which dictionary method returns a default value if a key doesn't exist?

get()

In regular expressions, which type of matching would match the longest possible pattern?

grëëdy

Dictionaries are unordered, contain _________ pairs

key-value

Which ones are examples of a mutable data type?

list, dictionary

In Python, which data type is considered mutable?

lists

Variables that "contain" list values do not actually store lists directly. What do they contain instead?

references

Which string method is used to right-justify a string?

rjust()

Which dictionary method sets a value if a key doesn't exist?

setdefault()

When does the findall() method return a list of tuples of strings?

when the Regex has numbers

What does a dictionary value with a key 'egg' and a value 100 look like?

{'egg':100}

What does the code for an empty dictionary look like?

{}


Conjuntos de estudio relacionados

Global Cold War and Decolonization

View Set

NUR 230: Chapter 3 Prepu questions

View Set

Chapter 16: Nursing Care of the Child With an Alteration in Intracranial Regulation/Neurologic Disorder

View Set

Chapter 42: The Child With Cardiovascular Dysfunction

View Set