Code multiple choice test

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

what does list_name.extend([element, element, ...]) do?

Adds a list of elements onto the end of an existing list

What does the following code print? time_of_day = ["morning", "afternoon", "evening"] for word in time_of_day: print "Good " + word

Good morning Good afternoon Good evening

Which is the following is not true about tuples

Tuples use parentheses to access individual elements, rather than square brackets

the list

a heterogenous, mutable data type that stores an ordered sequence of things

what does list_name.append(element) do?

adds elements to the end of a list one by one

what does tuple_name [num] [num] do?

can call the index of a tuple in a tuple

what does a list_name.count() do

counts how many of a particular element element exist in a list

what does list_name = [element, element, ...] do?

creates a list

what does tuple_name = (element, element, ...) do?

creates a tuple

what does import math do

imports math library

what does string.join(list_name) do?

joins list elements into a string concatenated with a given string

Which of the following Python programs creates a list with numbers 1 through 5?

my_list = [1, 2, 3, 4, 5]

Look at the following program: my_list = ["bananas", "oranges", "grapes", "pineapples", "apples"] # You pick the code that goes here... # ... # ... print my_list Pick the code that results in the following output: ['apples', 'bananas', 'grapes', 'oranges', 'pineapples']

my_list.sort()

Look at the following program: my_list = ["bananas", "oranges", "grapes", "pineapples", "apples"] # You pick the code that goes here... # ... # ... print my_list Pick the code that results in the following output: ['pineapples', 'oranges', 'grapes', 'apples']

my_list.sort() my_list.reverse() my_list.remove("bananas")

which of the following code snippets will correctly convert a string to a list

my_string = "hello" str_as_list = list(my_string)

What code below will print the following? Letter 1: T Letter 2: i Letter 3: m

name = "Tim" name_list = list(name) for index, value in enumerate(name_list): print "Letter " + str(index+1) + ": " + name_list[index]

what does pow(number,exponent) do?

raises a number to an exponent

what does list_name.remove() do?

removes the first occurrence of a particular element in a list

what does list_name.reverse() do?

reverses the order of elements inside a list

what does list_index, list_item in enumerate(list_name): commmands here (indented!) do?

saves both the index value and the list item at each loop iteration

what does string.split() do?

separates a line of text into list elements at whitespaces

what does list(string) do?

separates a string into list elements

what does list_name.sort() do?

sorts the elements in a list from least to greatest

What does Math.sqrt(number) do?

takes the square root of a number

what does tuple_name = (element,) do?

tuples need commas

Which of the following is the correct way to declare a tuple?

x = (1, 2, 3)

Tuple

A heterogenous, immutable data type that stores an ordered sequence of things

what does tuple_name = (element, element, ....) ...) do?

A tuple can exist inside a tuple


Conjuntos de estudio relacionados

Chapter 1 An Overview of Nutrition

View Set

Chapter 44 Assessment and Management of Patients with Biliary Disorders PrepU

View Set

Chapter 4 - Health Insurance Providers

View Set

Redox & Reduct. Multiple Choice IB Chemistry

View Set

A & P II exam 4 ( chapters 22-23)

View Set

Earth's Surface: Weathering and Soil

View Set

Prep U's - Chapter 54 - Drug Therapy for Anxiety and Insomnia

View Set