Complex Data Types in Python: Working with Lists & Tuples in Python

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

All of the following statements are ways in which lists and tuples are similar. Which one of these is NOT true?

Both, once created, cannot be updated

What is the result of executing this code? Code Editor: some_string = "Python" a, b, c, d = some_string

This is an error, "too many values to unpack"

All of the following statements are ways in which lists and tuples are different. Which one of these is true?

A list can be changed once creating, a tuple is immutable and cannot be changed

If you wanted to sort the elements in the list names_list in alphabetical order which of the following statements in Python are valid?

names_list.sort() names_list = sorted(names_list)

Which of the following statements about Python lists are true?

Lists are ordered collections Lists in Python can have elements of different data types

What will be the result of this slicing operation of the names_list? Code Editor: names_list = ['John', 'James', 'Lily', 'Emily', 'Nina'] names_list[::2]

['John', 'Lily', 'Nina']

Which of the following are valid complex data types in Python?

lists sets dictionaries

What is the result of executing this code? Code Editor: city = 'Los Angeles' city.find('x')

-1

If you want to count the number of times the name "John" appears in the names_list what function would you invoke?

names_list.count("John")

If you wanted to insert an element at index 2 in a particular list named names_list what is the function that you would invoke?

names_list.insert(2, "John")

Consider the list: Code Editor: some_list = ['a', 'b', 'c', 'd', 'e', 'f'] How do you slice this list to access the elements 'c', 'd'?

some_list[2:4]

Which of the following lines of code will print this string in reverse i.e. print out "olleH" Code Editor: some_str = "Hello"

some_str[::-1]


Set pelajaran terkait

Macroeconomics Review: Modules 22, 23, 25

View Set

advanced social psychology exam 2

View Set

Art History: Early Medieval Art [Quiz]

View Set

BAS 282: Overview of Marketing: SmartBook

View Set

Medical Office (front) continued

View Set