yield
statement of a generator and return a value of None.while
or for loop
and return to the start of the loop.Correct Answer:
I hope this helps! Let me know if you have any other questions.
Certification Questions & Certification Answers
any()
function will randomly return any item from the list.any()
function returns True if any item in the list evaluates to True. Otherwise, it returns False.any()
function takes as arguments the list to check inside, and the item to check for. If “any” of the items in the list match the item to check for, the function returns True.any()
function returns a Boolean value that answers the question “Are there any items in this list?”Correct Answer:
any()
function returns True if any item in the list evaluates to True. Otherwise, it returns False.example:
if any([True, False, False, False]) == True: print('Yes, there is True') >>> Yes, there is True
Correct Answer:
Explanation – deque
is used to create block chanin and in that there is first in first out approch, which means the last element to enter will be the first to leave.
maxValue = 255
max_value = 255
MAX_VALUE = 255
MaxValue = 255
Correct Answer:
MAX_VALUE = 255
Correct Answer:
def sum(a, b): # a = 1 # b = 2 # sum(a, b) = 3 return a + b
def sum(a, b): """ a = 1 b = 2 sum(a, b) = 3 """ return a + b
def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ return a + b
def sum(a, b): ''' a = 1 b = 2 sum(a, b) = 3 ''' return a + b
Correct Answer:
def sum(a, b): """ >>> a = 1 >>> b = 2 >>> sum(a, b) 3 """ return a + b
Explanation: Use “”” to start and end the docstring and use >>> to represent the output. If you write this correctly you can also run the doctest using build-in doctest module
Correct Answer:
Correct Answer:
fruits = ['Apples', 'Oranges', 'Bananas'] quantities = [5, 3, 4] prices = [1.50, 2.25, 0.89] #Desired output [('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89)]
output = [] fruit_tuple_0 = (first[0], quantities[0], price[0]) output.append(fruit_tuple) fruit_tuple_1 = (first[1], quantities[1], price[1]) output.append(fruit_tuple) fruit_tuple_2 = (first[2], quantities[2], price[2]) output.append(fruit_tuple) return output
i = 0 output = [] for fruit in fruits: temp_qty = quantities[i] temp_price = prices[i] output.append((fruit, temp_qty, temp_price)) i += 1 return output
groceries = zip(fruits, quantities, prices) return groceries >>> [ ('Apples', 5, 1.50), ('Oranges', 3, 2.25), ('Bananas', 4, 0.89) ]
i = 0 output = [] for fruit in fruits: for qty in quantities: for price in prices: output.append((fruit, qty, price)) i += 1 return output
Correct Answer:
i = 0 output = [] for fruit in fruits: temp_qty = quantities[i] temp_price = prices[i] output.append((fruit, temp_qty, temp_price)) i += 1 return output
defaultdict
will automatically create a dictionary for you that has keys which are the integers 0-10.defaultdict
forces a dictionary to only accept keys that are of the data type specified when you created the defaultdict
(such as strings or integers).defaultdict
with a nonexistent key, a new default key-value pair will be created for you instead of throwing a KeyError
.defaultdict
stores a copy of a dictionary in memory that you can default to if the original gets unintentionally modified.Correct Answer:
defaultdict
with a nonexistent key, a new default key-value pair will be created for you instead of throwing a KeyError
.-- This is a comment
# This is a comment
/_ This is a comment _\
// This is a comment
Correct Answer:
# This is a comment
None
.True
.Correct Answer:
None
.Intersect;union
Correct Answer:
Correct Answer:
fruit_info = { 'fruit': 'apple', 'count': 2, 'price': 3.5 }
fruit_info ['price'] = 1.5
my_list [3.5] = 1.5
1.5 = fruit_info ['price]
my_list['price'] == 1.5
Correct Answer:
fruit_info ['price'] = 1.5
Correct Answer:
Z = y.split(‘;’)
len(z)
Correct Answer:
Explanation:
y=”stuff;thing;junk”
len(z) ==> 3
y=”stuff;thing;junk;”
len(z) ==> 4
Correct Answer:
Example:
import numpy as np vector = np.random.rand(10000) matrix = a.reshape(100, 100) print(matrix.shape) (100, 100)
num_list = [21,13,19,3,11,5,18] num_list.sort() num_list[len(num_list)//2]
Correct Answer:
if/else
statement, used when testing for equality between objects.Correct Answer:
Explanation Attributes defined under the class, arguments goes under the functions. arguments usually refer as parameter, whereas attributes are the constructor of the class or an instance of a class.
Correct Answer:
set
list
None
dictionary
Correct Answer:
list
. You can only build a stack from scratch.
.delete()
methodpop(my_list)
del(my_list)
.pop()
methodCorrect Answer:
.pop()
methodexample:
my_list = [1,2,3] my_list.pop(0) my_list >>>[2,3]
Correct Answer:
__init__
method makes classes aware of each other if more than one class is defined in a single code file.__init__
method is included to preserve backwards compatibility from Python 3 to Python 2, but no longer needs to be used in Python 3.__init__
method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.__init__
method initializes any imports you may have included at the top of your file.Correct Answer:
__init__
method is a constructor method that is called automatically whenever a new object is created from a class. It sets the initial state of a new object.Example:
class test: def __init__(self): print('I came here without your permission lol') pass t1 = test() >>> 'I came here without your permission lol'
Correct Answer:
Correct Answer:
Example:
import math radius = [1,2,3] area = list(map(lambda x: round(math.pi*(x**2), 2), radius)) area >>> [3.14, 12.57, 28.27]
Correct Answer:
Correct Answer:
Correct Answer:
Explanation: – The synax for map()
function is list(map(function,iterable)
. the simple area finder using map would be like this
import math radius = [1,2,3] area = list(map(lambda x: round(math.pi*(x**2), 2), radius)) area >>> [3.14, 12.57, 28.27]
def print_alpha_nums(abc_list, num_list): for char in abc_list: for num in num_list: print(char, num) return print_alpha_nums(['a', 'b', 'c'], [1, 2, 3])
a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3
['a', 'b', 'c'], [1, 2, 3]
aaa bbb ccc 111 222 333
a 1 2 3 b 1 2 3 c 1 2 3
Correct Answer:
a 1 a 2 a 3 b 1 b 2 b 3 c 1 c 2 c 3
Correct Answer:
all()
function returns a Boolean value that answers the question “Are all the items in this list the same?all()
function returns True if all the items in the list can be converted to strings. Otherwise, it returns False.all()
function will return all the values in the list.all()
function returns True if all items in the list evaluate to True. Otherwise, it returns False.Correct Answer:
all()
function returns True if all items in the list evaluate to True. Otherwise, it returns False.Explaination:
all()
returns true if all in the list are True, see example below
test = [True,False,False,False] if all(test) is True: print('Yeah all are True') else: print('There is an imposter') >>> There is an imposter
Correct Answer:
Correct Answer:
Explanation: the lambda notation is basically an anonymous function that can take any number of arguments with only single expression (i.e, cannot be overloaded). It has been introducted in other programming languages, such as C++ and Java. The lambda notation allows programmers to "bypass" function declaration.
Correct Answer:
None
.Correct Answer:
Correct Answer:
How many microprocessors it would take to run your code in less than one second
How many lines of code are in your code file
The amount of space taken up in memory as a function of the input size
How many copies of the code file could fit in 1 GB of memory
Correct Answer:
The amount of space taken up in memory as a function of the input size
Correct Answer:
Correct Answer:
Correct Answer:
fruit_info['variety'] == 'Red Delicious'
fruit_info['variety'] = 'Red Delicious'
red_delicious = fruit_info['variety']
red_delicious == fruit_info['variety']
Correct Answer:
fruit_info['variety'] = 'Red Delicious'
(Answer format may vary. Game and roll (or dice_roll) should each be called with no parameters.)
>>> dice = Game() >>> dice.roll()
>>> dice = Game(self) >>> dice.roll(self)
>>> dice = Game() >>> dice.roll(self)
>>> dice = Game(self) >>> dice.roll()
Correct Answer:
>>> dice = Game() >>> dice.roll()
fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}
fruit_info =('fruit': 'apple', 'count': 2,'price': 3.5 ).dict()
fruit_info = ['fruit': 'apple', 'count': 2,'price': 3.5 ].dict()
fruit_info = to_dict('fruit': 'apple', 'count': 2, 'price': 3.5)
Correct Answer:
fruit_info = {'fruit': 'apple', 'count': 2, 'price': 3.5}
my_set = {0, 'apple', 3.5}
my_set = to_set(0, 'apple', 3.5)
my_set = (0, 'apple', 3.5).to_set()
my_set = (0, 'apple', 3.5).set()
Correct Answer:
my_set = {0, 'apple', 3.5}
Correct Answer:
class Game(LogicGame): pass
def Game(LogicGame): pass
def Game.LogicGame(): pass
class Game.LogicGame(): pass
Correct Answer:
class Game(LogicGame): pass
Explanation: The parent class which is inherited is passed as an argument to the child class. Therefore, here the first option is the right answer.
Correct Answer:
9. Classes — Python 3.10.2 documentation
https://docs.python.org/3/tutorial/classes.html
def __init__(self, attr1, attr2): attr1 = attr1 attr2 = attr2
def __init__(attr1, attr2): attr1 = attr1 attr2 = attr2
def __init__(self, attr1, attr2): self.attr1 = attr1 self.attr2 = attr2
def __init__(attr1, attr2): self.attr1 = attr1 self.attr2 = attr2
Correct Answer:
def __init__(self, attr1, attr2): self.attr1 = attr1 self.attr2 = attr2
Explanation: When instantiating a new object from a given class, the __init__()
method will take both attr1
and attr2
, and set its values to their corresponding object attribute, that’s why the need of using self.attr1 = attr1
instead of attr1 = attr1
.
Correct Answer:
my_game = class.Game()
my_game = class(Game)
my_game = Game()
my_game = Game.create()
Correct Answer:
my_game = Game()
my_list = ['kiwi', 'apple', 'banana']
Correct Answer:
Correct Answer:
Correct Answer:
Correct Answer:
def sum(a, b): """ sum(4, 3) 7 sum(-4, 5) 1 """ return a + b
def sum(a, b): """ >>> sum(4, 3) 7 >>> sum(-4, 5) 1 """ return a + b
def sum(a, b): """ # >>> sum(4, 3) # 7 # >>> sum(-4, 5) # 1 """ return a + b
def sum(a, b): ### >>> sum(4, 3) 7 >>> sum(-4, 5) 1 ### return a + b
Correct Answer:
def sum(a, b): """ >>> sum(4, 3) 7 >>> sum(-4, 5) 1 """ return a + b
explanation – use ”’ to start the doc and add output of the cell after >>>
Correct Answer:
Correct Answer:
Correct Answer:
num_list = [1,2,3,4,5]
num_list.remove(2)
print(num_list)
Correct Answer:
explanation:
num_list = [1,2,3,4,5]
num_list.pop(2)
[1,2,4,5]
num_list.remove(2)
[1,3,4,5]
Options 1:
a = np.array([1,2,3,4])
print(a[[False, True, False, False]])
Correct Answer:
Options 2:
table = np.array([
[1,3],
[2,4]])
print(table.max(axis=1))
[2, 4]
[3, 4]
[4]
[1,2]
Correct Answer:
[3, 4]
Correct Answer:
def getMaxNum(list_of_nums): # body of function goes here
func get_max_num(list_of_nums): # body of function goes here
func getMaxNum(list_of_nums): # body of function goes here
def get_max_num(list_of_nums): # body of function goes here
Correct Answer:
def get_max_num(list_of_nums): # body of function goes here
explanation for 52 & 53
PEP 8 — Style Guide for Python Code | Python.org
The official home of the Python Programming Language
https://www.python.org/dev/peps/pep-0008/
fruits = {'Apples': 5, 'Oranges': 3, 'Bananas': 4}
fruit_names = [x in fruits.keys() for x]
fruit_names = for x in fruits.keys() *
fruit_names = [x for x in fruits.keys()]
fruit_names = x for x in fruits.keys()
Correct Answer:
fruit_names = [x for x in fruits.keys()]
Correct Answer:
self
means that no other arguments are required to be passed into the method.self
method; it’s just historic computer science jargon that Python keeps to stay consistent with other programming languages.self
refers to the instance whose method was called.self
refers to the class that was inherited from to create the object using self
.Correct Answer:
self
refers to the instance whose method was called.Simple example
class my_secrets: def __init__(self, password): self.password = password pass instance = my_secrets('1234') instance.password >>>'1234'
yield
statement of a generator and return a value of None.while
or for loop
and return to the start of the loop.Correct Answer:
self
refers to the class that was inherited from to create the object using self
.self
method. It’s just legacy computer science jargon that Python keeps to stay consistent with other programming languages.self
means that no other arguments are required to be passed into the method.self
refers to the instance whose method was called.Correct Answer:
self
refers to the instance whose method was called.Explanation: – Try running the example of the Q45 without passing self
argument inside the __init__
, you’ll understand the reason. You’ll get the error like this __init__() takes 0 positional arguments but 1 was given
, this means that something is going inside even if haven’t specified, which is instance itself.
Correct Answer:
Correct Answer:
Correct Answer:
count, fruit, price = (2, 'apple', 3.5)
tuple assignment
tuple unpacking
tuple matching
tuple duplication
Correct Answer:
tuple unpacking
Correct Answer:
None
.Correct Answer:
Correct Answer:
&&
=
==
||
Correct Answer:
==
5 != 6
yes
False
True
None
Correct Answer:
True
Explanation – !=
is equivalent to not equal to in python
Correct Answer:
import numpy as np np.ones([1,2,3,4,5])
Correct Answer:
{x for x in range(100) if x%3 == 0}
Correct Answer:
Correct Answer:
college_years = ['Freshman', 'Sophomore', 'Junior', 'Senior'] return list(enumerate(college_years, 2019))
[('Freshman', 2019), ('Sophomore', 2020), ('Junior', 2021), ('Senior', 2022)]
[(2019, 2020, 2021, 2022), ('Freshman', 'Sophomore', 'Junior', 'Senior')]
[('Freshman', 'Sophomore', 'Junior', 'Senior'), (2019, 2020, 2021, 2022)]
[(2019, 'Freshman'), (2020, 'Sophomore'), (2021, 'Junior'), (2022, 'Senior')]
Correct Answer:
[(2019, 'Freshman'), (2020, 'Sophomore'), (2021, 'Junior'), (2022, 'Senior')]
def count_recursive(n=1): if n > 3: return print(n) count_recursive(n + 1)
1 1 2 2 3 3
3 2 1
3 3 2 2 1 1
1 2 3
Correct Answer:
1 2 3
Correct Answer:
Correct Answer:
Correct Answer:
Simple Example
i = 1 while i<6: print('Countdown:',i) i = i + 1
num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") elif num_people > 4; print("There are some people in the pool.") elif num_people > 0; print("There are a few people in the pool.") else: print("There is no one in the pool.")
num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") if num_people > 4: print("There are some people in the pool.") if num_people > 0: print("There are a few people in the pool.") else: print("There is no one in the pool.")
num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") elif num_people > 4: print("There are some people in the pool.") elif num_people > 0: print("There are a few people in the pool.") else: print("There is no one in the pool.")
if num_people > 10; print("There is a lot of people in the pool.") if num_people > 4: print("There are some people in the pool.") if num_people > 0: print("There are a few people in the pool.") else: print("There is no one in the pool.")
Correct Answer:
num_people = 5 if num_people > 10: print("There is a lot of people in the pool.") elif num_people > 4: print("There are some people in the pool.") elif num_people > 0: print("There are a few people in the pool.") else: print("There is no one in the pool.")
slot
dictionary
queue
sorted list
Correct Answer:
dictionary
[10,9,8,7,6,5,4,3,2,1]
Correct Answer:
import math
print(math.pow(2,10)) # prints 2 elevated to the 10th power
print(2^10)
print(2**10)
y = [x*2 for x in range(1,10)]
print(y)
y = 1
for i in range(1,10):
y = y * 2
print(y)
Correct Answer:
print(2**10)
Correct Answer:
Correct Answer:
namedtuple
members and refer to them that way, similarly to how you would access keys in dictionary
.tuple
.namedtuples
are just as memory efficient as regular tuples
.namedtuples
because they are available in the standard library.Correct Answer:
namedtuples
because they are available in the standard library.**We need to import it using from collections import namedtuple
**
Correct Answer:
Correct Answer:
Correct Answer:
Explanation:
Stack uses the first in first out approach
Correct Answer:
Correct Answer:
with
keyword lets you choose which application to open the file in.with
keyword acts like a for
loop, and lets you access each line in the file one by one.with
keyword for opening a file in Python.with
keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.Correct Answer:
with
keyword in Python, Python will make sure the file gets closed, even if an exception or error is thrown.7. Input and Output — Python 3.10.2 documentation
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
Correct Answer:
Correct Answer:
mixin
to force a function to accept an argument at runtime even if the argument wasn’t included in the function’s definition.mixin
to allow a decorator to accept keyword arguments.mixin
to make sure that a class’s attributes and methods don’t interfere with global variables and functions.mixin
to define that functionality.Correct Answer:
mixin
to define that functionality.Correct Answer:
LinkedIn PHP Skill Assessment Quiz Options:
Correct Answer:
LinkedIn Python Skill Assessment Quiz Options:
number = 3
print (f"The number is {number}")
The number is 3
the number is 3
THE NUMBER IS 3
Correct Answer:
The number is 3
This page was last edited on 12th March, 2024 at 8:53 AM (UTC).