Programming

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/15

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

16 Terms

1
New cards

and - statement

Evaluates to True if both conditions are True

2
New cards

or - statement

Evaluates to True if at least one condition is True

3
New cards

type()

Function to confirm the data type of a variable

4
New cards

How do you check if the substring "apple" is in the string assigned to fruits? fruits = "banana, cherry, apple"

"apple" in fruits

5
New cards

Which line of code correctly checks the data type of item_price to see if it is a float?

6
New cards
7
New cards

Which method is used to add an item to the end of a list in Python?

append()

8
New cards

How do you get a value from a dictionary without knowing if the key exists, to avoid an error?

dictionary.get(“key”)

9
New cards

# List of recent sales descriptions

recent_sales = [

"Buy 2 Get 1 Free: Red Bull",

"50% Off Holiday Cookies",

"$1 Off Baking Soda"

]

# Grocery inventory

inventory = {

"Holiday Cookies": [(434, 1.99), 30, False, recent_sales[1]],

"Ice Cream Sandwich": [(556, 0.89), 14, True, None]

}

# Value to check

print(inventory["Holiday Cookies"][3]) → What will the following print statement return?

10
New cards

What will the following code output?

my_list = [1, 2, 3]

my_list.append([4, 5])

print(my_list)

11
New cards

How can you retrieve a value from a dictionary (dict) by its key (key)?

  • dict[key]

  • dict.get(key)

12
New cards

What is the difference between a tuple and a list?

The primary difference is that lists are mutable (can be changed) while tuples are immutable (cannot be changed).

13
New cards

What will this code do?

my_tuple = (1, 2)

my_tuple[1] = 5

print(my_tuple)

Tuples are immutable, so attempting to change an element directly will result in an error.

14
New cards

What will this code do?

my_list = [1, 2, 3]

new_list = my_list

new_list.append(4)

print(my_list)

It will print [1, 2, 3, 4]. Assigning new_list to my_list makes new_list a reference to my_list. Therefore, changes to new_list also affect my_list.

15
New cards

How do you update a value (value) in a dictionary? (dict)

dict[key] = value

16
New cards

How would you change "green" to "yellow"?

colors = ["red", "green", "blue"]

colors[1] = “yellow”

To change an element in a list, you can directly access it using its index. The index of "green" is 1, so using colors[1] = "yellow" updates "green" to "yellow". The other options are incorrect because they either reference the wrong index or use nonexistent methods for lists.