Programming python certification: Functions, Dictionaries, Sets, Tuples, Booleans, Data Types, and Strings

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

If you do not know the number of arguments that will be passed into your function, there is a prefix you can add in the function definition, which prefix? def my_function(___kids): print("The youngest child is " + kids[2])

*

If you do not know the number of keyword arguments that will be passed into your function, there is a prefix you can add in the function definition, which prefix? def my_function(___kid): print("His last name is " + kid["lname"])

**

Use a range of indexes to print the third, fourth, and fifth item in the tuple. fruits = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango") print(fruits[_____])

2:5

The statement below would print a Boolean value, which one? print(10 == 9)

False

The statement below would print a Boolean value, which one? print(bool(0))

False

The statement below would print a Boolean value, which one? print(10 < 9)

False

The statement below would print a Boolean value, which one? print(10 > 9)

True

The statement below would print a Boolean value, which one? print(bool("abc"))

True

The following code example would print the data type of x, what data type would that be? x = True print(type(x))

bool

Use the clear method to empty the car dictionary. car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

car.clear()

Use the get method to print the value of the "model" key of the car dictionary. car = { "brand": "Ford", "model": "Mustang", "year": 1964 } print(_______)

car.get("model")

Use the pop method to remove "model" from the car dictionary. car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

car.pop("model")

Add the key/value pair "color" : "red" to the car dictionary. car = { "brand": "Ford", "model": "Mustang", "year": 1964 }

car["color"] = "red"

Change the "year" value from 1964 to 2020. car = { "brand": "Ford", "model": "Mustang", "year": 1964 } _______ = _____

car["year"], 2020

Create a function named my_function. _______: print("Hello from a function")

def my_function()

The following code example would print the data type of x, what data type would that be? x = {"name" : "John", "age" : 36} print(type(x))

dictionary

The following code example would print the data type of x, what data type would that be? x = 20.5 print(type(x))

float

Inside a function with two parameters, print the first parameter. def my_function(fname, lname): print(_____)

fname

Use the add method to add "orange" to the fruits set. fruits = {"apple", "banana", "cherry"}

fruits.add("orange")

Use the discard method to remove "banana" from the fruits set. fruits = {"apple", "banana", "cherry"}

fruits.discard("banana")

Use the remove method to remove "banana" from the fruits set. fruits = {"apple", "banana", "cherry"}

fruits.remove("banana")

Use the correct method to add multiple items (more_fruits) to the fruits set. fruits = {"apple", "banana", "cherry"} more_fruits = ["orange", "mango", "grapes"]

fruits.update(more_fruits)

Use negative indexing to print the last item in the tuple. fruits = ("apple", "banana", "cherry") print(_____)

fruits[-1]

Use the correct syntax to print the first item in the fruits tuple. fruits = ("apple", "banana", "cherry") print(_____)

fruits[0]

Check if "apple" is present in the fruits set. fruits = {"apple", "banana", "cherry"} if "apple" ___ fruits: print("Yes, apple is a fruit!")

in

The following code example would print the data type of x, what data type would that be? x = 5 print(type(x))

int

Use the correct syntax to print the number of items in the fruits tuple. fruits = ("apple", "banana", "cherry") print(_____)

len(fruits)

Use the "len" method to print the length of the string. x = "Hello World" print(_____)

len(x)

The following code example would print the data type of x, what data type would that be? x = ["apple", "banana", "cherry"] print(type(x))

list

Execute a function named my_function. def my_function(): print("Hello from a function")

my_function()

Replace the character H with a J. txt = "Hello World" txt = txt._____(___, ___)

replace "H" "J"

Let the function return the x parameter + 5. def my_function(x): __________

return x + 5

The following code example would print the data type of x, what data type would that be? x = "Hello World" print(type(x))

str

The following code example would print the data type of x, what data type would that be? x = ("apple", "banana", "cherry") print(type(x))

tuple

Convert the value of txt to lower case. txt = "Hello World" txt = _____

txt.lower()

Return the string without any whitespace at the beginning or the end. txt = " Hello World " x = _____

txt.strip()

Convert the value of txt to upper case. txt = "Hello World" txt = _____

txt.upper()

Get the first character of the string txt. txt = "Hello World" x = _____

txt[0]

Get the characters from index 2 to index 4 (llo). txt = "Hello World" x = _____

txt[2:5]

Insert the correct syntax to add a placeholder for the age parameter. age = 36 txt = "My name is John, and I am _____" print(txt.format(age))

{}


Set pelajaran terkait

3/18 Personal Pronouns 人称代词(我,你,他/她/它)

View Set

Chapter 12: Spinal Cord and Spinal Nerves - Assingment

View Set

ATI PROCTORED EXAM - MATERNAL NEWBORN

View Set

Correlation vs. Causation: Differences & Definition

View Set

ATI RN Pediatric Nursing Online Practice 2023 B

View Set

Questions with "tu aimes" (Safia)

View Set

七上历史chapter4 section 4 the new kingdom and kush

View Set