Beginners

  1. What is the output of the following code?
    1. str = "pynative"
    2. print(str[1:3])
  • py
  • yn
  • pyn
  • yna
  1. What is the output of the following code?
    1. var1 = 1
    2. var2 = 2
    3. var3 = "3"
    4. print(var1 + var2 + var3)
  • 6
  • 33
  • 123
  • Error. Mixing operators between numbers and strings are not supported
  1. What is the output of the following code?
    1. for i in range(10, 15, 1):
    2. print(i, end=', ')
  • 10, 11, 12, 13, 14,
  • 10, 11, 12, 13, 14, 15,
  1. What is the output of the following code? ```python salary = 8000 def printSalary(): salary = 12000 print(“Salary:”, salary)

printSalary() print(“Salary:”, salary)

  1. - [x] Salary: 12000
  2. Salary: 8000
  3. - [ ] Salary: 8000
  4. Salary: 12000
  5. - [ ] The program failed with errors
  6. 5. Which operator has higher precedence in the following list?
  7. - [ ] % Modulus
  8. - [ ] & BitWise AND
  9. - [ ] **, Exponent
  10. - [ ] > Comparison
  11. 6. What is the output of the following code?
  12. ```python
  13. var = "James Bond"
  14. print(var[2::-1])
  • Jam
  • dno
  • maJ
  • dnoB semaJ
  1. What is the output of the following code?
    1. p, q, r = 10, 20 ,30
    2. print(p, q, r)
  • 10 20
  • 10 20 30
  • Error: invalid syntax
  1. What is the output of the following code?
    1. sampleList = ["Jon", "Kelly", "Jessa"]
    2. sampleList.append(2, "Scott")
    3. print(sampleList)
  • The program executed with errors
  • [‘Jon’, ‘Kelly’, ‘Scott’, ‘Jessa’]
  • [‘Jon’, ‘Kelly’, ‘Jessa’, ‘Scott’]
  • [‘Jon’, ‘Scott’, ‘Kelly’, ‘Jessa’]
  1. A string is immutable in Python? Every time when we modify the string, Python Always create a new String and assign a new string to that variable.
  • True
  • False
  1. Can we use the “else” clause for loops? for example:
    1. for i in range(1, 5):
    2. print(i)
    3. else:
    4. print("this is else block statement" )
  • No
  • Yes
  1. The in operator is used to check if a value exists within an iterable object container such as a list. Evaluates to true if it finds a variable in the specified sequence and false otherwise.
  • True
  • False
  1. What is the Output of the following code?
    1. for x in range(0.5, 5.5, 0.5):
    2. print(x)
  • [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5]
  • [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
  • The Program executed with errors
  1. What is the output of the following code?
    1. def calculate (num1, num2=4):
    2. res = num1 * num2
    3. print(res)
    4. calculate(5, 6)
  • 20
  • The program executed with errors
  • 30
  1. What is the output of the following
    1. x = 36 / 4 * (3 + 2) * 4 + 2
    2. print(x)
  • 182.0
  • 37
  • 117
  • The Program executed with errors
  1. What is the output of the following code?
    1. valueOne = 5 ** 2
    2. valueTwo = 5 ** 3
    3. print(valueOne)
    4. print(valueTwo)
  • 10
    15
  • 25
    125
  • Error: invalid syntax
  1. What is the output of the following code?
    1. listOne = [20, 40, 60, 80]
    2. listTwo = [20, 40, 60, 80]
    3. print(listOne == listTwo)
    4. print(listOne is listTwo)
  • True
    True
  • True
    False
  • False
    True
  1. What is the output of the following code?
    1. sampleSet = {"Jodi", "Eric", "Garry"}
    2. sampleSet.add(1, "Vicki")
    3. print(sampleSet)
  • {‘Vicki’, ‘Jodi’, ‘Garry’, ‘Eric’}
  • {‘Jodi’, ‘Vicki’, ‘Garry’, ‘Eric’}
  • The program executed with error
  1. What is the output of the following code?
    1. var = "James" * 2 * 3
    2. print(var)
  • JamesJamesJamesJamesJamesJames
  • JamesJamesJamesJamesJames
  • Error: invalid syntax

Variables and Data Types

  1. What is the output of the following code
    1. print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
  • False True False True
  • True True False True
  • True True False True
  • False True True True
  1. What is the output of the following code
    1. x = 50
    2. def fun1():
    3. x = 25
    4. print(x)
    5. fun1()
    6. print(x)
  • NameError
  • 25
    25
  • 25
    50
  1. What is the result of print(type([]) is list)
  • False
  • True
  1. Select all the valid String creation in Python
  • str1 = “str1”
  • str1 = ‘str1’
  • str1 = “‘str1”‘
  • str1 = str(“str1”)
  1. What is the output of the following variable assignment
    1. x = 75
    2. def myfunc():
    3. x = x + 1
    4. print(x)
    5. myfunc()
    6. print(x)
  • Error
  • 76
  • 1
  • None
  1. What is the data type of the following
    1. aTuple = (1, 'Jhon', 1+3j)
    2. print(type(aTuple[2:3]))
  • list
  • complex
  • tuple
  1. What is the data type of print(type(10))
  • float
  • integer
  • int
  1. What is the result of print(type({}) is set)
  • True
  • False
  1. Select the right way to create a string literal Ault'Kelly
  • str1 = ‘Ault\‘Kelly’
  • str1 = ‘Ault\’Kelly’
  • str1 = “””Ault’Kelly”””
  1. In Python 3, what is the type of type(range(5))
  • int
  • list
  • range
  1. What is the output of the following code
    1. def func1():
    2. x = 50
    3. return x
    4. func1()
    5. print(x)
  • 50
  • NameError
  • None
  1. Please select the correct expression to reassign a global variable **x** to 20 inside a function fun1()
    1. x = 50
    2. def fun1():
    3. # your code to assign global x = 20
    4. fun1()
    5. print(x) # it should print 20
  • global x =20
  • global var x
    x = 20
  • global.x = 20
  • global x
    x = 20
  1. What is the data type of print(type(0xFF))
  • number
  • hexint
  • hex
  • int

Operators and Expresion

  1. What is the output of the following Python code
    1. x = 10
    2. y = 50
    3. if (x ** 2 > 100 and y < 100):
    4. print(x, y)
  • 100 500
  • 10 50
  • None
  1. What is the output of print(2 * 3 ** 3 * 4)
  • 216
  • 864
  1. What is the output of print(10 - 4 * 2)
  • 2
  • 12
  1. Which of the following operators has the highest precedence?
  • not
  • &
  • *
  • +
  1. What is the output of the following code
    1. x = 100
    2. y = 50
    3. print(x and y)
  • True
  • 100
  • False
  • 50
  1. What is the output of print(2 ** 3 ** 2)
  • 64
  • 512
  1. What is the value of the following Python Expression print(36 / 4)
  • 9.0
  • 9
  1. What is the output of print(2%6)
  • ValueError
  • 0.33
  • 2
  1. What is the output of the following code
    1. x = 6
    2. y = 2
    3. print(x ** y)
    4. print(x // y)
  • 66
    0
  • 36
    0
  • 66
    3
  • 36
    3
  1. What is the output of the following addition (+) operator
    1. a = [10, 20]
    2. b = a
    3. b += [30, 40]
    4. print(a)
    5. print(b)
  • [10, 20, 30, 40]
    [10, 20, 30, 40]
  • [10, 20]
    [10, 20, 30, 40]
  1. What is the output of the expression print(-18 // 4)
  • -4
  • 4
  • -5
  • 5
  1. What is the output of the following code
    print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
  • True True False True
  • False True True True
  • True True False True
  • False True False True
  1. 4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?
    1. a = 4
    2. b = 11
    3. print(a | b)
    4. print(a >> 2)
  • 15
    1
  • 14
    1
  1. What is the output of the following assignment operator
    1. y = 10
    2. x = y += 2
    3. print(x)
  • 12
  • 10
  • SynatxError
  1. Bitwise shift operators (<<, >>) has higher precedence than Bitwise And(&) operator
  • False
  • True

Input and Output

  1. Which of the following is incorrect file handling mode in Python
  • wb+
  • ab
  • xr
  • ab+
  1. What is the output of the following print() function
    print(sep='--', 'Ben', 25, 'California')
  • Syntax Error
  • Ben–25–California
  • Ben 25 California
  1. What is the output of the following code
    1. print('PYnative ', end='//')
    2. print(' is for ', end='//')
    3. print(' Python Lovers', end='//')
  • [ ] PYnative /

    1. is for /<br /> Python Lovers /<br />
  • [ ] PYnative //

    1. is for //<br /> Python Lovers //
  • [ ] PYnative // is for // Python Lovers//

  • PYnative / is for / Python Lovers/
  1. What is the output of print('%x, %X' % (15, 15))
  • 15 15
  • F F
  • f f
  • f F
  1. Use the following file to predict the output of the code
    test.txt Content:
    1. aaa
    2. bbb
    3. ccc
    4. ddd
    5. eee
    6. fff
    7. ggg
    Code:
    1. f = open("test.txt", "r")
    2. print(f.readline(3))
    3. f.close()
  • bbb
  • Syntax Error
  • aaa
  • aa
  1. In Python3, Whatever you enter as input, the input() function converts it into a string
  • False
  • True
  1. What is true for file mode x
  • create a file if the specified file does not exist
  • Create a file, returns an error if the file exists
  • Create a file if it doesn’t exists else Truncate the existed file
  1. Which of the following is incorrect file handling mode in Python
  • r
  • x
  • t+
  • b
  1. What is the output of print('[%c]' % 65)
  • 65
  • A
  • [A]
  • Syntax Error
  1. What is the output of the following print() function
    print('%d %d %.2f' % (11, '22', 11.22))
  • 11 22 11.22
  • TypeError
  • 11 ’22’ 11.22
  1. What will be displayed as an output on the screen
    1. x = float('NaN')
    2. print('%f, %e, %F, %E' % (x, x, x, x))
  • nan, nan, NAN, NAN
  • nan, NaN, nan, NaN
  • NaN, NaN, NaN, NaN,
  1. In Python3, which functions are used to accept input from the user
  • input()
  • raw_input()
  • rawinput()
  • string()

Functions

  1. Choose the correct function declaration of fun1() so that we can execute the following function call successfully
    1. fun1(25, 75, 55)
    2. fun1(10, 20)
  • def fun1(**kwargs)
  • No, it is not possible in Python
  • def fun1(args*)
  • def fun1(*data)
  1. Python function always returns a value
  • False
  • True
  1. What is the output of the following code
    1. def outerFun(a, b):
    2. def innerFun(c, d):
    3. return c + d
    4. return innerFun(a, b)
    5. res = outerFun(5, 10)
    6. print(res)
  • 15
  • Syntax Error
  • (5, 10)
  1. What is the output of the following displayPerson() function call
    1. def displayPerson(*args):
    2. for i in args:
    3. print(i)
    4. displayPerson(name="Emma", age="25")
  • TypeError
  • Emma
    25
  • name
    age
  1. Select which is true for Python function
  • A Python function can return only a single value
  • A function can take an unlimited number of arguments.
  • A Python function can return multiple values
  • Python function doesn’t return anything unless and until you add a return statement
  1. What is the output of the following function call
    1. def outerFun(a, b):
    2. def innerFun(c, d):
    3. return c + d
    4. return innerFun(a, b)
    5. return a
    6. result = outerFun(5, 10)
    7. print(result)
  • 5
  • 15
  • (15, 5)
  • Syntax Error
  1. Given the following function fun1() Please select the correct function calls
    1. def fun1(name, age):
    2. print(name, age)
  • fun1(name=’Emma’, age=23)
  • fun1(name=’Emma’, 23)
  • fun1(‘Emma’, 23)
  1. Select which true for Python function
  • A function is a code block that only executes when it is called.
  • Python function always returns a value.
  • A function only executes when it is called and we can reuse it in a program
  • Python doesn’t support nested function
  1. What is the output of the add() function call
    1. def add(a, b):
    2. return a+5, b+5
    3. result = add(3, 2)
    4. print(result)
  • 15
  • 8
  • (8, 7)
  • Syntax Error
  1. What is the output of the following function call
    1. def fun1(num):
    2. return num + 25
    3. fun1(5)
    4. print(num)
  • 25
  • 5
  • NameError
  1. What is the output of the following display() function call
    1. def display(**kwargs):
    2. for i in kwargs:
    3. print(i)
    4. display(emp="Kelly", salary=9000)
  • TypeError
  • Kelly
    9000
  • (’emp’, ‘Kelly’)
    (‘salary’, 9000)
  • emp
    salary
  1. What is the output of the following function call
    1. def fun1(name, age=20):
    2. print(name, age)
    3. fun1('Emma', 25)
  • Emma 25
  • Emma 20

Conditions and Loops

  1. Given the nested if-else structure below, what will be the value of xafter code execution completes
    1. x = 0
    2. a = 0
    3. b = -5
    4. if a > 0:
    5. if b < 0:
    6. x = x + 5
    7. elif a > 5:
    8. x = x + 4
    9. else:
    10. x = x + 3
    11. else:
    12. x = x + 2
    13. print(x)
  • 2
  • 0
  • 3
  • 4
  1. What is the output of the following nested loop
    1. for num in range(10, 14):
    2. for i in range(2, num):
    3. if num%i == 1:
    4. print(num)
    5. break
  • 10
    11
    12
    13
  • 11
    13
  1. Select which is true for for loop
  • Python’s for loop used to iterates over the items of list, tuple, dictionary, set, or string
  • else clause of for loop is executed when the loop terminates naturally
  • else clause of for loop is executed when the loop terminates abruptly
  • We use for loop when we want to perform a task indefinitely until a particular condition is met
  1. Given the nested if-else below, what will be the value x when the code executed successfully
    1. x = 0
    2. a = 5
    3. b = 5
    4. if a > 0:
    5. if b < 0:
    6. x = x + 5
    7. elif a > 5:
    8. x = x + 4
    9. else:
    10. x = x + 3
    11. else:
    12. x = x + 2
    13. print(x)
  • 0
  • 4
  • 2
  • 3
  1. What is the output of the following loop
    1. for l in 'Jhon':
    2. if l == 'o':
    3. pass
    4. print(l, end=", ")
  • J, h, n,
  • J, h, o, n,
  1. What is the value of x
    1. x = 0
    2. while (x < 100):
    3. x+=2
    4. print(x)
  • 101
  • 99
  • None of the above, this is an infinite loop
  • 100
  1. What is the value of the var after the for loop completes its execution
    var = 10
    for i in range(10):
     for j in range(2, 10, 1):
         if var % 2 == 0:
             continue
             var += 1
     var+=1
    else:
     var+=1
    print(var)
    
  • 20
  • 21
  • 10
  • 30
  1. What is the output of the following range() function
    for num in range(2,-5,-1):
     print(num, end=", ")
    
  • 2, 1, 0
  • 2, 1, 0, -1, -2, -3, -4, -5
  • 2, 1, 0, -1, -2, -3, -4
  1. What is the output of the following nested loop
    numbers = [10, 20]
    items = ["Chair", "Table"]
    for x in numbers:
    for y in items:
     print(x, y)
    
  • 10 Chair
    10 Table
    20 Chair
    20 Table
  • 10 Chair
    10 Table
  1. What is the output of the following if statement
    a, b = 12, 5
    if a + b:
    print('True')
    else:
    print('False')
    
  • False
  • True
  1. if -3 will evaluate to true
  • True
  • False
  1. What is the value of x after the following nested for loop completes its execution
    x = 0
    for i in range(10):
    for j in range(-1, -10, -1):
    x += 1
    print(x)
    
  • 99
  • 90
  • 100
  1. What is the output of the following for loop and range() function
    for num in range(-2,-5,-1):
    print(num, end=", ")
    
  • -2, -1, -3, -4
  • -2, -1, 0, 1, 2, 3,
  • -2, -1, 0
  • -2, -3, -4,

Numbers

  1. What is the output of the following math function
    import math
    print(math.ceil(252.4))
    print(math.floor(252.4))
    
  • 252
    252
  • 252
    253
  • 253
    252
  1. Select all correct float numbers
  • a = 10.1256
  • b = -10.5
  • c = 42e3
  • d = -68.7e100
  1. What is the output of the following round() function call
    print(round(100.2563, 3))
    print(round(100.000056, 3))
    
  • 100.256
    100
  • 100.256
    100.000
  • 100.256
    100.0
  1. Select which is right for Python integers
  • An integer is a whole number that can be positive or negative
  • In Python 3, Integers have unlimited precision
  1. What is the output of the following code
    print(0b101)
    print(0o10)
    print(0x1F)
    
  • 101
    10
    1F
  • 5
    8
    31
  • Syntax Error: Invalid Token
  1. What is the output of the following number conversion
    z = complex(1.25)
  • (1.25+0j)
  • Value Error: Missing an imaginary part of a complex number
  1. In Python 3, the integer ranges from -2,147,483,648 to +2,147,483,647
  • False
  • True
  1. What is the output of the following code
    print(int(2.999))
  • ValueError: invalid literal for int()
  • 3
  • 2
  1. What is the output of the following isinstance() function
    from numbers import Number
    from decimal import Decimal
    from fractions import Fraction
    print(isinstance(2.0, Number))
    print(isinstance(Decimal('2.0'), Number))
    print(isinstance(Fraction(2, 1), Number))
    print(isinstance("2", Number))
    
  • True
    False
    True
    True
  • True
    True
    True
    True
  • True
    False
    True
    False
  • True
    True
    True
    False
  1. What is the type of the following variable
    x = -5j
  • int
  • complex
  • real
  • imaginary
  1. What is the output of print(abs(-45.300))
  • 45.3
  • -45.3
  • -45.300
  • 45.300
  1. What is the output of the following number comparison function call
    print( (1.1 + 2.2) == 3.3 )
  • True
  • False

Strings

  1. Choose the correct function to get the character from ASCII number
  • ascii(‘number)
  • char(number)
  • chr(number)
  1. Select the correct output of the following String operations
    myString = "pynative"
    stringList = ["abc", "pynative", "xyz"]
    print(stringList[1] == myString)
    print(stringList[1] is myString)
    
  • true false
  • true true
  1. What is the output of the following code
    str1 = "My salary is 7000";
    str2 = "7000"
    print(str1.isdigit())
    print(str2.isdigit())
    
  • False
    True
  • False
    False
  • True
    False
  1. Select the correct output of the following String operations
    strOne = str("pynative")
    strTwo = "pynative"
    print(strOne == strTwo)
    print(strOne is strTwo)
    
  • false false
  • true true
  • true false
  • false true
  1. Strings are immutable in Python, which means a string cannot be modified.
  • True
  • False
  1. Which method should I use to convert String "welcome to the beautiful world of python" to "Welcome To The Beautiful World Of Python"
  • capitalize()
  • title()
  1. Choose the correct function to get the ASCII code of a character
  • char(‘char’)
  • ord(‘char’)
  • ascii(‘char’)
  1. Select the correct output of the following String operations
    str = "my name is James bond";
    print (str.capitalize())
    
  • My Name Is James Bond
  • TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
  • My name is james bond
  1. Guess the correct output of the following String operations
    str1 = 'Welcome'
    print(str1*2)
    
  • WelcomeWelcome
  • TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
  1. What is the output of the following string operations
    str = "My salary is 7000";
    print(str.isalnum())
    
  • True
  • False
  1. Guess the correct output of the following code?
    str1 = "PYnative"
    print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
    
  • PYn PYnat ive PYnativ vitanYP
  • Yna PYnat tive PYnativ vitanYP
  • Yna PYnat tive PYnativ PYnativ
  1. Select the correct output of the following String operations
    str1 = 'Welcome'
    print (str1[:6] + ' PYnative')
    
  • Welcome PYnative
  • WelcomPYnative
  • Welcom PYnative
  • WelcomePYnative
  1. Python does not support a character type; a single character is treated as strings of length one.
  • False
  • True
  1. What is the output of the following string comparison
    print("John" > "Jhon")
    print("Emma" < "Emm")
    
  • True
    False
  • False
    False
  1. Select the correct output of the following String operations
    str1 = "my isname isisis jameis isis bond";
    sub = "is";
    print(str1.count(sub, 4))
    
  • 5
  • 6
  • 7

Lists

  1. Select all the correct options to join two lists in Python
    listOne  =  ['a', 'b', 'c', 'd']
    listTwo =  ['e', 'f', 'g']
    
  • newList = listOne + listTwo
  • newList = extend(listOne, listTwo)
  • newList = listOne.extend(listTwo)
  • newList.extend(listOne, listTwo)
  1. What is the output of the following list comprehension
    resList = [x+y for x in ['Hello ', 'Good '] for y in ['Dear', 'Bye']]
    print(resList)
    
  • [‘Hello Dear’, ‘Hello Bye’, ‘Good Dear’, ‘Good Bye’]
  • [‘Hello Dear’, ‘Good Dear’, ‘Hello Bye’, ‘Good Bye’]
  1. What is the output of the following list function? ```python sampleList = [10, 20, 30, 40, 50] sampleList.append(60) print(sampleList)

sampleList.append(60) print(sampleList)


- [ ]  [10, 20, 30, 40, 50, 60]<br /> [10, 20, 30, 40, 50, 60]
- [ ]  [10, 20, 30, 40, 50, 60]<br /> [10, 20, 30, 40, 50, 60, 60]

4. What is the output of the following list function?
```python
sampleList = [10, 20, 30, 40, 50]
sampleList.pop()
print(sampleList)
sampleList.pop(2)
print(sampleList)
  • [20, 30, 40, 50]
    [10, 20, 40]
  • [10, 20, 30, 40]
    [10, 20, 30, 50]
  • [10, 20, 30, 40]
    [10, 20, 40]
  1. What is the output of the following
    aList = [5, 10, 15, 25]
    print(aList[::-2])
    
  • [15, 10, 5]
  • [10, 5]
  • [25, 10]
  1. What is the output of the following code
    list1 = ['xyz', 'zara', 'PYnative']
    print (max(list1))
    
  • PYnative
  • zara
  1. What is the output of the following list assignment
    aList = [4, 8, 12, 16]
    aList[1:4] = [20, 24, 28]
    print(aList)
    
  • [4, 20, 24, 28, 8, 12, 16]
  • [4, 20, 24, 28]
  1. What is the output of the following code?
    sampleList = [10, 20, 30, 40]
    del sampleList[0:6]
    print(sampleList)
    
  • []
  • list index out of range.
  • [10, 20]
  1. What is the output of the following list operation
    aList = [10, 20, 30, 40, 50, 60, 70, 80]
    print(aList[2:5])
    print(aList[:4])
    print(aList[3:])
    
  • [20, 30, 40, 50]
    [10, 20, 30, 40]
    [30, 40, 50, 60, 70, 80]
  • [30, 40, 50]
    [10, 20, 30, 40]
    [40, 50, 60, 70, 80]
  1. What is the output of the following
    l = [None] * 10
    print(len(l))
    
  • 10
  • 0
  • Syntax Error
  1. What is the output of the following list operation
    sampleList = [10, 20, 30, 40, 50]
    print(sampleList[-2])
    print(sampleList[-4:-1])
    
  • 40
    [20, 30, 40]
  • IndexError: list index out of range
  1. Select all the correct options to copy a list
    aList = ['a', 'b', 'c', 'd']
  • newList = copy(aList)
  • newList = aList.copy()
  • newList.copy(aList)
  • newList = list(aList)
  1. What is the output of the following code
    my_list = ["Hello", "Python"]
    print("-".join(my_list))
    
  • HelloPython-
  • Hello-Python
  • -HelloPython
  1. What is the output of the following
    aList = [1, 2, 3, 4, 5, 6, 7]
    pow2 =  [2 * x for x in aList]
    print(pow2)
    
  • [2, 4, 6, 8, 10, 12, 14]
  • [2, 4, 8, 16, 32, 64, 128]
  1. What is the output of the following code
    aList = ["PYnative", [4, 8, 12, 16]]
    print(aList[0][1])    
    print(aList[1][3])
    
  • P 8
    Y 16
  • P
    12
  • Y
    16
  1. In Python, list is mutable
  • False
  • True

Set

  1. What is the output of the following code
    sampleSet = {"Yellow", "Orange", "Black"}
    print(sampleSet[1])
    
  • Yellow
  • Syntax Error
  • Orange
  1. What is the output of the following set operation.
    set1 = {"Yellow", "Orange", "Black"}
    set2 = {"Orange", "Blue", "Pink"}
    set1.difference_update(set2)
    print(set1)
    
  • {‘Black’, ‘Yellow’}
  • {‘Yellow’, ‘Orange’, ‘Black’, ‘Blue’, ‘Pink’}
  1. What is the output of the following
    sampleSet = {"Yellow", "Orange", "Black"}
    sampleSet.add("Blue")
    sampleSet.add("Orange")
    print(sampleSet)
    
  • {‘Blue’, ‘Orange’, ‘Yellow’, ‘Orange’, ‘Black’}
  • {‘Blue’, ‘Orange’, ‘Yellow’, ‘Black’}
  1. The isdisjoint() method returns True if none of the items are present in both sets, otherwise, it returns False.
  • True
  • False
  1. Select which is true for Python set
  • Sets are unordered.
  • Set doesn’t allow duplicate
  • sets are written with curly brackets {}
  • set Allows duplicate
  • set is immutable
  • a set object does support indexing
  1. What is the output of the following union operation
    set1 = {10, 20, 30, 40}
    set2 = {50, 20, "10", 60}
    set3 = set1.union(set2)
    print(set3)
    
  • {40, 10, 50, 20, 60, 30}
  • {40, ’10’, 50, 20, 60, 30}
  • {40, 10, ’10’, 50, 20, 60, 30}
  • SynatxError: Different types cannot be used with sets
  1. What is the output of the following set operation
    set1 = {"Yellow", "Orange", "Black"}
    set2 = {"Orange", "Blue", "Pink"}
    set3 = set2.difference(set1)
    print(set3)
    
  • {‘Yellow’, ”Black’, ‘Pink’, ‘Blue’}
  • {‘Pink’, ‘Blue’}
  • {‘Yellow’, ”Black’}
  1. What is the output of the following code
    aSet = {1, 'PYnative', ('abc', 'xyz'), True}
    print(aSet)
    
  • TypeError
  • {‘PYnative’, 1, (‘abc’, ‘xyz’), True}
  • {‘PYnative’, 1, (‘abc’, ‘xyz’)}
  1. What is the output of the following
    set1 = {10, 20, 30, 40, 50}
    set2 = {60, 70, 10, 30, 40, 80, 20, 50}
    print(set1.issubset(set2))
    print(set2.issuperset(set1))
    
  • False
    False
  • True
    True
  1. Select all the correct options to remove “Orange” from the set.
    sampleSet = {"Yellow", "Orange", "Black"}
    
  • sampleSet.pop(“Orange”)
  • sampleSet.discard(“Orange”)
  • sampleSet.discard(“Orange”)
  • del sampleSet [“Orange”]
  1. The symmetric_difference() method returns a set that contains all items from both sets, but not the items that are present in both sets.
  • False
  • True
  1. What is the output of the following code
    aSet = {1, 'PYnative', ['abc', 'xyz'], True}
    print(aSet)
    
  • {1, ‘PYnative’, [‘abc’, ‘xyz’]}
  • {1, ‘PYnative’, [‘abc’, ‘xyz’], True}
  • TypeError
  1. The union() method returns a new set with all items from both sets by removing duplicates
  • True
  • False
  1. What is the output of the following set operation
    sampleSet = {"Yellow", "Orange", "Black"}
    sampleSet.update(["Blue", "Green", "Red"])
    print(sampleSet)
    
  • {‘Yellow’, ‘Orange’, ‘Red’, ‘Black’, ‘Green’, ‘Blue’}
  • {‘Yellow’, ‘Orange’, ‘Black’, [“Blue”, “Green”, “Red”]}
  • TypeError: update() doesn’t allow list as a argument.
  1. What is the output of the following
    sampleSet = {"Yellow", "Orange", "Black"}
    sampleSet.discard("Blue")
    print(sampleSet)
    
  • {‘Yellow’, ‘Orange’, ‘Black’}
  • KeyError: ‘Blue’
  1. Select all the correct ways to copy two sets
  • set2 = set1.copy()
  • set2 = set1
  • set2 = set(set1)
  • set2.update(set1)

Dictionary

  1. Please select all correct ways to empty the following dictionary
    student = { 
    "name": "Emma", 
    "class": 9, 
    "marks": 75 
    }
    
  • del student
  • del student[0:2]
  • student.clear()
  1. In Python, Dictionaries are immutable
  • False
  • True
  1. Select the correct way to print Emma’s age.
    student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'},
            2: {'name': 'Mike', 'age': '22', 'sex': 'Male'}}
    
  • student[0][1]
  • student[1][“age”]
  • student[0][“age”]
  1. Select the correct ways to get the value of marks key.
    student = {
    "name": "Emma",
    "class": 9,
    "marks": 75
    }
    
  • m = student.get(2)
  • m = student.get(‘marks’)
  • m = student[2])
  • m = student[‘marks’])
  1. Select the all correct way to remove the key ‘marks‘ from a dictionary
    student = { 
    "name": "Emma", 
    "class": 9, 
    "marks": 75 
    }
    
  • student.pop(“marks”)
  • del student[“marks”]
  • student.popitem()
  • dict1.remove(“key2”)
  1. Select correct ways to create an empty dictionary
  • sampleDict = {}
  • sampleDict = dict()
  • sampleDict = dict{}
  1. What is the output of the following
    sampleDict = dict([
    ('first', 1),
    ('second', 2),
    ('third', 3)
    ])
    print(sampleDict)
    
  • [ (‘first’, 100), (‘second’, 200), (‘third’, 300) ]
  • Options: SyntaxError: invalid syntax
  • {‘first’: 1, ‘second’: 2, ‘third’: 3}
  1. Select the correct way to access the value of a history subject
    sampleDict = { 
    "class":{ 
       "student":{ 
          "name":"Mike",
          "marks":{ 
             "physics":70,
             "history":80
          }
       }
    }
    }
    
  • sampleDict[‘class’][‘student’][‘marks’][‘history’]
  • sampleDict[‘class’][‘student’][‘marks’][1]
  • sampleDict[‘class’][0][‘marks’][‘history’]
  1. What is the output of the following dictionary operation
    dict1 = {"name": "Mike", "salary": 8000}
    temp = dict1.get("age")
    print(temp)
    
  • KeyError: ‘age’
  • None
  1. Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type.
  • True
  • False
  1. Select all correct ways to copy a dictionary in Python
  • dict2 = dict1.copy()
  • dict2 = dict(dict1.items())
  • dict2 = dict(dict1)
  • dict2 = dict1
  1. What is the output of the following code
    dict1 = {"key1":1, "key2":2}
    dict2 = {"key2":2, "key1":1}
    print(dict1 == dict2)
    
  • True
  • False
  1. Dictionary keys must be immutable
  • True
  • False
  1. What is the output of the following dictionary operation
    dict1 = {"name": "Mike", "salary": 8000}
    temp = dict1.pop("age")
    print(temp)
    
  • KeyError: ‘age’
  • None

Tuple

  1. Select which is true for Python tuple
  • A tuple maintains the order of items
  • A tuple is unordered
  • We cannot change the tuple once created
  • We can change the tuple once created
  1. What is the type of the following variable
    aTuple = ("Orange")
    print(type(aTuple))
    
  • list
  • tuple
  • array
  • str
  1. What is the output of the following
    aTuple = "Yellow", 20, "Red"
    a, b, c = aTuple
    print(a)
    
  • (‘Yellow’, 20, ‘Red’)
  • TyepeError
  • Yellow
  1. What is the output of the following code
    aTuple = (100, 200, 300, 400, 500)
    print(aTuple[-2])
    print(aTuple[-4:-1])
    
  • IndexError: tuple index out of range
  • 400
    (200, 300, 400)
  1. What is the output of the following
    tuple1 = (1120, 'a')
    print(max(tuple1))
    
  • TypeError
  • 1120
  • ‘a’
  1. What is the output of the following code
    aTuple = (100, 200, 300, 400, 500)
    aTuple[1] = 800
    print(aTuple)
    
  • TypeError
  • (100, 800, 200, 300, 400, 500)
  • (800, 100, 200, 300, 400, 500)
  1. Select true statements regarding the Python tuple
  • We can remove the item from tuple but we cannot update items of the tuple
  • We cannot delete the tuple
  • We cannot remove the items from the tuple
  • We cannot update items of the tuple.
  1. What is the output of the following tuple operation
    aTuple = (100,)
    print(aTuple * 2)
    
  • TypeError
  • (100, 100)
  • (200)
  1. What is the output of the following tuple operation
    aTuple = (100, 200, 300, 400, 500)
    aTuple.pop(2)
    print(aTuple)
    
  • (100, 200, 400, 500)
  • (100, 300, 400, 500)
  • AttributeError
  1. A Python tuple can also be created without using parentheses
  • False
  • True
  1. Choose the correct way to access value 20 from the following tuple
    aTuple = ("Orange", [10, 20, 30], (5, 15, 25))
    
  • aTuple[1:2][1]
  • aTuple1:2
  • aTuple[1:2][1]
  • aTuple[1][1]
  1. What is the output of the following
    aTuple = (10, 20, 30, 40, 50, 60, 70, 80)
    print(aTuple[2:5], aTuple[:4], aTuple[3:])
    
  • (30, 40, 50) (10, 20, 30, 40) (40, 50, 60, 70, 80)
  • (20, 30, 40, 50) (10, 20, 30, 40) (30, 40, 50, 60, 70, 80)

Random Data Generation

  1. To generate a random secure Universally unique ID which method should I use
  • uuid.uuid4()
  • uuid.uuid1()
  • uuid.uuid3()
  • random.uuid()
  1. str = “PYnative”.
    Choose the correct function to pick a single character from a given string randomly.
  • random.sample(str)
  • random.choice(str)
  • random.get(str, 1)
  1. To Generate a random secure integer number, select all the correct options.
  • random.SystemRandom().randint()
  • random.System.randint()
  • secrets.randbelow()
  1. Choose the correct function from the following list to get the random integer between 99 to 200, which is divisible by 3.
  • random.randrange(99, 200, 3)
  • random.randint(99, 200, 3)
  • random.random(99, 200, 3)
  1. numberList = [100, 200, 300, 400, 500]
    Choose the correct function to get 3 elements from the list randomly in such a way that each element of the list has a different probability of being selected.
  • random.choices(numberList, weights=(10, 5, 15, 20, 50), k=3)
  • random.choice(numberList, weights=(10, 5, 15, 20, 50), k=3)
  • random.sample(numberList, weights=(10, 5, 15, 20, 50), k=3)
  1. Which method should i use to capture and change the current state of the random generator
  • [ ] random.getstate()

    random.setstate(state)
    
  • [ ] random.currentstate()

    random.setcurrentstate(state)
    
  1. I want to generate a random secure hex token of 32 bytes to reset the password, which method should I use
  • secrets.hexToken(32)
  • secrets.hex_token(32)
  • secrets.tokenHex(32)
  • secrets.token_hex(32)
  1. random.seed() method is used to initialize the pseudorandom number generator. The random module uses the seed value as a base to generate a random number. If seed value is not present, it takes the system’s current time.
  • True
  • False
  1. To generate a random float number between 20.5 to 50.5, which function of a random module I need to use
  • random.random(20.5, 50.5)
  • random.uniform(20.5, 50.5)
  • random.randrange(20.5, 50.5)
  • random.randfloat(20.5, 50.5)
  1. Which method should I use to get 4 elements from the following list randomly
    samplelist = [20, 40, 60, 80, 100, 120, 140, 160, 180, 200]
    
  • random.choice(samplelist, 4)
  • random.sample(samplelist, 4)