l=[1, 0, 2, 0, 'hello', '', []]
list(filter(bool, l))
- [1, 0, 2, ‘hello’, ”, []]
- Error1
- [1, 2, ‘hello’]
- [1, 0, 2, 0, ‘hello’, ”, []]
Click to View Answer
[1, 2, ‘hello’]
f = foo()
format(f)
- str()
- format()
- _str_()
- _format_()
Click to View Answer
- [ ] __str__()
def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
- Error
- None
- False
- True
Click to View Answer
- [ ] True
z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z
- {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
- {‘abc’, ‘p’, ‘q’, ‘san’}
- {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
- {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
Click to View Answer
- [ ] {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
print("abc. DEF".capitalize())
- Abc. def
- abc. def
- Abc. Def
- ABC. DEF
Click to View Answer
- [ ] Abc. def
def foo():
try:
return 1
finally:
return 2
k = foo()
print(k)
- 1
- 2
- 3
- error, there is more than one return statement in a single try-finally block
Click to View Answer
- [ ] 2
- Ability of a class to derive members of another class as a part of its own definition
- Means of bundling instance variables and methods in order to restrict access to certain class members
- Focuses on variables and passing of variables to functions
- Allows for implementation of elegant software that is well designed and easily modified
Click to View Answer
- [ ] Ability of a class to derive members of another class as a part of its own definition
Suppose B is a subclass of A, to invoke the init method in A from B, what is the line of code you should write?
- A.init(self)
- B.init(self)
- A.init(B)
- B.init(A)
Click to View Answer
- [ ] A.__init__(self)
class A:
def __init__(self, x= 1):
self.x = x
class der(A):
def __init__(self,y = 2):
super().__init__()
self.y = y
def main():
obj = der()
print(obj.x, obj.y)
main()
- Error, the syntax of the invoking method is wrong
- The program runs fine but nothing is printed
- 1 0
- 1 2
Click to View Answer
- [ ] 1 2
- Determines the object name of any value
- Determines the class name of any value
- Determines class description of any value
- Determines the file name of any value
Click to View Answer
- [ ] Determines the class name of any value
- It allows the programmer to think at a more abstract level
- There is less program code to write
- The program will have a more elegant design and will be easier to maintain and update
- Program code takes up less space
Click to View Answer
- [ ] The program will have a more elegant design and will be easier to maintain and update
A class in which one or more methods are only implemented to raise an exception is called an abstract class.
- True
- False
Click to View Answer
- [ ] True
- Ability of a class to derive members of another class as a part of its own definition
- Means of bundling instance variables and methods in order to restrict access to certain class members
- Focuses on variables and passing of variables to functions
- Allows for implementation of elegant software that is well designed and easily modified
Click to View Answer
- [ ] Means of bundling instance variables and methods in order to restrict access to certain class members
sentence = 'we are humans'
matched = re.match(r'(.*) (.*?) (.*)', sentence)
print(matched.groups())
- (‘we’, ‘are’, ‘humans’)
- (we, are, humans)
- (‘we’, ‘humans’)
- ‘we are humans’
Click to View Answer
- [ ] (‘we’, ‘are’, ‘humans’)
import turtle
t=turtle.Pen()
for i in range(0,4):
t.forward(100)
t.left(120)
- square
- rectangle
- triangle
- kite
Click to View Answer
- [ ] triangle
- terminate the process f
- terminate the process f if f is not responding
- close the file descriptor f
- return an integer telling how close the file pointer is to the end of file
Click to View Answer
- [ ] close the file descriptor f
- random.choice([3, 6])
- random.randrange(3, 6)
- 3 + random.randrange(3)
- 3 + random.randrange(4)
Click to View Answer
- [ ] 3 + random.randrange(4)
x = [[0], [1]]
print((' '.join(list(map(str, x))),))
- (‘[0] [1]’,)
- (’01’)
- [0] [1]
- 01
Click to View Answer
- [ ] (‘[0] [1]’,)
elements = [0, 1, 2]
def incr(x):
return x+1
print(list(map(elements, incr)))
- [1, 2, 3]
- [0, 1, 2]
- error
- none of the mentioned
Click to View Answer
- [ ] error
- getopt
- os
- getarg
- main
Click to View Answer
- [ ] getopt
- When you open a file for reading, if the file does not exist, an error occurs
- When you open a file for writing, if the file does not exist, a new file is created
- When you open a file for writing, if the file exists, the existing file is overwritten with the new file
- All of the mentioned
Click to View Answer
- [ ] All of the mentioned
l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)
- True
- False
- Error
- Address of l1
Click to View Answer
- [ ] False
z=set('abc')
z.add('san')
z.update(set(['p', 'q']))
z
- {‘abc’, ‘p’, ‘q’, ‘san’}
- {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
- {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
- {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
Click to View Answer
- [ ] {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
- Lock is owned by a thread while RLock is owned by many.
- Lock is owned by none while RLock is owned by many.
- Lock and RLock both primitives are owned by a single thread.
- Lock and RLock both primitives are owned by many.
Click to View Answer
- [ ] Lock is owned by none while RLock is owned by many.
- Semaphore holds a counter for the number of release() calls minus the number of acquire() calls, plus an initial value but bounded semaphore doesn't.
- Bounded semaphore holds a counter for the number of release() calls minus the number of acquire() calls, plus an initial value but semaphore doesn't.
- A bounded semaphore makes sure its current value doesn’t exceed its initial value while semaphore doesn't.
- A semaphore makes sure its current value doesn’t exceed its initial value while bounded semaphore doesn't.
Click to View Answer
- [ ] A bounded semaphore makes sure its current value doesn’t exceed its initial value while semaphore doesn't.
-
Write a Python function to find the largest element in an array or list.
-
Given an array of integers, find two numbers such that they add up to a specific target sum.
-
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if:
- Open brackets must be closed by the same type of brackets.
- Open brackets must be closed in the correct order.
- Every close bracket has a corresponding open bracket of the same type.
Example 1: Input: s = "()" Output: true Example 2: Input: s = "()[]{}" Output: true Example 3: Input: s = "(]" Output: false
-
finding the minimum value in a sliding window of a fixed size in an array