In: Computer Science
Given a list of fruits, fruits = ["apple", "pear", "banana", "cherry" ]
which expression(s) will return the last two items in fruits in this order : cherry, banana?
a) fruits[-3:-1]
b) fruits[-1:-len(fruits) + 2:-1]
c) fruits[-1:-3:-1]
d) fruits[:-3:-1]
Which Python variable names are invalid?
a) 12MonthsTotal_Pay
b) TotalPay$
c) Total_January2019
d) JanuaryRateln%
what is the output of executing the code segment?
a, b, c = False, True, False
if a or b:
print('A', end = ' ')
else:
print('B', end = ' ')
if not b:
print('C', end = ' ' )
elif c :
print('D', end = ' ' )
else:
print('E', end = ' ' )
print()
a) A E
b) B E
c) A
d) None of the above
Suppose k = ["apple", "banana", "cherry"]
Which statement(s) when executed does not cause a run-time error?
a) del k["apple"]
b) k.sort(reverse = True)
c) k.get("apple", 'Not found')
d) All three statement do not cause a run-time error.
Solution(1) : Option(C) and Option(D) both are correct options here. Please check out the output in the below code for the same.
Solution(2) : Option(A) , Option(B) , and Option(D) both are correct options here because we can not declare a variable in these three ways as these declarations are invalid. Please check out the output in the below code for the same.
Solution(3) : Option(A) " A E " is the correct option. Please check out the output in the below code for the same.
Solution(4) : Option(B) " k.sort(reverse = True) " is the correct option because it will not create any run time error while execution. Please check out the output in the below code for the same.