Python Essentials 1:
Python Essentials 2:
Python Essentials - Final Test:
Warning!
For searching questions, CTRL+F .if you want correct answer.. type manually.Don't Copy & paste questions in search space.
If you copy paste questions in search options means.. you can't find answer
What is the expected output of the following snippet?
a = True b = False a = a or b b = a and b a = a or b print(a, b)
False FalseTrue FalseFalse TrueTrue False
What is the expected output of the following snippet?
print(len([i for i in range(0, -2)]))
3120
How many stars
*will the following snippet send to the console?i = 4 while i > 0 : i -= 2 print("*") if i == 2: break else: print("*")twoonezero- The snippet will enter an infinite loop, constantly printing one
*per line
What is the
sys.stdoutstream normally associated with?- The printer
- The keyboard
- A
nulldevice - The screen
What is the excepted output of the following snippet?
class X: pass class Y(X): pass class Z(Y): pass x = X() z = Z() print(isinstance(x, z), isinstance(z, X))True TrueTrue FalseFalse TrueFalse False
What is the excepted output of the following snippet?
class A: def __init__(self,name): self.name = name a = A("class") print(a)classname- A number
- A string ending with a long hexadecimal number
What is the excepted result of executing the following code?
class A: pass class B: pass class C(A, B): pass print(issubclass(C, A) and issubclass(C, B))- The code will print True
- The code will raise an exception
- The code will print an empty line
- The code will print
False
What is the excepted output of the following code?
from datetime import datetime datetime = datatime(2019, 11, 27, 11, 27, 22)] print(datetime.strftime('%Y/%m/%d %H:%M:%S'))19/11/27 11:27:222019/Nov/27 11:27:222019/11/27 11:27:222019/November/27 11:27:22
What is the excepted output of the following code?
my_string_1 = 'Bond' my_string_2 = 'James Bond' print(my_string_1.isalpha(), my_string_2.isalpha())
- False True
- True True
- False False
- True False
The meaning of a Keyword argument is determined by its:
- both name and value assigned to it
- position within the argument list
- connection with existing variables
- value only
Knowing that the function named
m, and the code contains the followingimportstatement:from f import mChoose the right way to invoke the function:
- mod.f()
- The function cannot be invoked because the
importstatement is invalid - f()
- mod:f()
The
Exceptionclass contains a property namedargs-what is it?- A dictionary
- A list
- A string
- A tuple
What is PEP 8?
- A document that provides coding conventions and style guide for the C code computing the C implementation of Python
- A document that describes the development and release schedule for Python versions
- A document that describes an extension to Python’s import mechanism which improves sharing of Python source code files
- A document that provides coding conventions and style guide for Python code
Which is the expected behavior of the following snippet?
def fun(x): return 1 if x % 2 != else 2 print(fun(fun(1)))- The program will output
None - The code will cause a runtime error
- The program will output
2 - The program will output
1
- The program will output
Which operator would you use to check whether two values are equal?
===is===
What is the name of the directory/folder created by Python used to store
pycfiles?__pycfiles__pyc____pycache____cache__
What can you do if you want tell your module users that a particular variable should not be accessed directly?
- Start its name with
__or__ - Start its name with a capital letter
- Use its number instead of its name
- Build its name with lowercase letters only
- Start its name with
What is the expected output of the following snippet?
d = ('one': 1, 'three': 3, 'two':2) for k in sorted(d.values()): print(k, end=' ')1 2 33 1 23 2 12 3 1
Select the true statements.(Select two answers)
- The first parameter of a class method dose not have to be named self
- The first parameter of a class method must be named self
- If a class contains the
__init__method, it can return a value - If a class contains the
__init__method, it cannot return any value
Select the true statements. (Select two answers)
- PyPI is short for Python Package Index
- PyPI is the only existing Python repository
- PyPI is one of many existing Python repository
- PyPI is short for Python Package Installer
What is the expected output of the following snippet?
t = (1, 2, 3, 4) t = t[-2:-1] t = t[-1] print(t)
(3)(3,)333
What is the expected effect of running the following code?
class A: def __init__(self, v): self._a = v + 1 a = A(0) print(a._a)- The code will raise an
AttributeErrorexception - The code will output
1 - The code will output
2 - The code will output
0
- The code will raise an
Which of the following functions provide by the
osmodule are available in both Windows and Unix? (Select two answers)chdir()getgid()getgroups()mkdir()
What is the expected output of the following piece of code?
v = 1 + 1 // 2 + 1 / 2 + 2 print(v)
4.033.54
If
sis a stream opened in read mode, the following line:q = s.readlines()
will assign
qas :dictionarytupleliststring
Which of the following sentences is true about the snippet below?
str_1 = 'string' str_2 = str_1[:]
str_1is longer thanstr_2str_1andstr_2are different (but equal) stringsstr_1andstr_2are different names of the same stringstr_2is longer thanstr_1
What is the expected result of executed the following code?
class A: def __init__(self): pass def f(self): return 1 def g(): return self.f() a = A() print(a.g())- The code will output
True - The code will output
0 - The code will output
1 - The code will raise an exception
- The code will output
What is the expected output of the following code, located in the file
module.py?print(__name__)
mainmodle.py__main____module.py__
What is the excepted output of the following code?
def a(x): def b(): return x + x return b x = a('x) y = a('') print(x() + y())xxxxxxxxxxxxx
What is the excepted behavior of the following piece of code?
x = 16 while x > 0: print('*', end='') x //= 2The code will output *****- The code will output
*** - The code will output
* - The code will error an infinite loop
A package directory/folder may contain a file intended to initialize the package. What is its name?
init.py__init.py____init__.__init__.py
If there is a
finally:branch inside thetry:block, we can say that:- the
finally:branch will always be executed - the
finally:branch won’t be executed if any of theexcept:branch is executed - the
finally:branch won’t be executed if no exception is raised - the
finally:branch will be executed when there is noelse:branch
- the
What value will be assigned to the
xvariable?z = 2 y = 1 x = y < z or z > y and y > z or z < y
TrueFalse01
If you want to write a byte array’s content to a stream, which method can you use?
writeto()writefrom()write()writebytearray()
What is the expected behavior of the following snippet?
try: raise Exception except: print("c") except BaseException: print("a") except Exception: print("b")- The code will cause an error
- The code will output
b - The code will output
c - The code will output
a
What is true about the following code snippet?
def fun(par2, par1): return par2 + par1 print(fun(par2 = 1, 2))- The code is erroneous
- The code will output
3 - The code will output
2 - The code will output
1
What is the expected output of the following piece of code?
x, y, z = 3, 2, 1 z, y, x = x, y, z print(x, y, z)
2 1 31 2 23 2 11 2 3
What is the expected output of the following snippet?
d = {} d['2'] = [1, 2] d['1'] = [3, 4] for x in d.keys(): print(d[x][1], end="")24311342
What is the expected output of the following snippet?
try: raise Exception except BaseException: print("a", end='') else: print("b", end='') finnaly: print("c")bcaabac
If the class constructor is declare as below:
class Class: def __init__(self): passwhich one of the assignment is valid?
object = Class()object = Class(1,2)object = Class(None)object = Class(1)
What is the expected output of the following code?
from datetime import timedelta delta = timedelta(weeks = 1, days = 7, hours = 11) print(delta)
7 days, 11:00:002 weeks, 11:00:001 week, 7 days, 11 hours14 days, 11:00:00
What is the expected output of the following piece of code if the user enters two lines containing
1and2respectively?y = input() x = input() print(x + y)
221123
What is the expected behavior of the following snippet?
my_string = 'abcdef' def fun(s): del s[2] return s print(fun(my_string))
- The program will cause an error
- The program will output
abdef - The program will output
acdef - The program will output
abcef
What is true about the following snippet?
def fun(d, k, v): d[k] = v my_dictionary = {} print(fun(my_dictionary, '1', 'v'))- The code is erroneous
- The code will output
None - The code will output
v - The code will output
1
What is the expected output of the following code?
class A: A = 1 def __init__(self): self.a = 0 print(hasattr(A, 'A'))False10True
What is the expected behavior of the following code?
x = """ """ print(len(x))
- The code will output
2 - The code will output
3 - The code will cause an error
- The code will output
1
- The code will output
What is the expected output of the following code?
import calendar c = calendar.Calendar(calendar.SUNDAY) for weekday in c.iterweekdays(): print(weekday, end=" ")7 1 2 3 4 5 66 0 1 2 3 4 5Su Mo Tu We Th Fr SaSu
What is the expected output of the following code?
def fun(n): s = ' ' for i in range(n): s += '*' yield s for x in fun(3): print(x, end='')**********2****
What is the expected output of the following code?
t = (1, ) t = t[0] + t[0] print(t)
2(1, )(1, 1)1
What is the expected result of executing the following code?
class A: def a(self): print('a') class B: def a(self): print('b') class C(A, B): def c(self): self.a() o = C() o.c()- The code will print
c - The code will print
a - The code will raise an exception
- The code will print
b
- The code will print
What is the expected behavior of the following code snippet?
my_list = [1, 2, 3, 4] my_list = list(map(lambda x: 2*x, my_list)) print(my_list)
- The code will cause a runtime error
- The code will output
1 2 3 4 - the code will output
10 - The code will output
2 4 6 8
What is the expected behavior of the following piece of code?
d = {1: 0, 2: 1, 3: 2, 0: 1} x = 0 for y in range(len(d)): x = d[x] print(x)- The code will output
0 - The code will output
1 - The code will cause a runtime error
- The code will output
2
- The code will output
What pip operation would you use to check what Python package have been installed so far?
showlisthelpdir
What is true about the following line of code?
print(len((1, )))
- The code will output
0 - The code is erroneous
- The code will output
1 - The code will output
2
- The code will output
Which line properly invokes the function defined as below?
def fun(a, b, c=0): # function bodyfun(b=0, b=0)fun(a=1, b=0, c=0)fun(1, c=2)fun(0)
What is the expected behavior of the following code?
import os os.makedirs('pictures/thumbnails') os.rmdir('pictures')- The code will delete both the
picturesandthumbnailsdirectories - The code will delete the
picturesdirectory only - The code will raise an error
- the code will delete the
thumbnailsdirectory only
- The code will delete both the
What is true about the following piece of code?
print("a", "b", "c", sep=" ' ")- The code is erroneous
- The code will output
abc - The code will output
a'b'c - The code will output
a b c
What is the expected behavior of the following code?
x = "\" print(len(x))
- The code will output
3 - The code will cause an error
- The code will output
a2 - The code will output
1
- The code will output
What is the expected output of the following code?
class A: A = 1 def __init__(self, v=2): self.v = v +A.A A.A += 1 def set(self, v): self.v +=v A.A += 1 return a = A() a.set(2) print(a.v)7135
How many empty lines will the following snippet send to the console?
my_list = [[c for c in range(r)] for r in range(3)] for element in my_list: if len(element) < 2: print()twothreezeroone
Python Essentials 1:
Python Essentials 2:
Python Essentials - Final Test:
