• Python question of the day

    What would be the output of executing the following code:
    print((lambda x: 3*x // 3 / x % 3)(17))
     1
     1.0
     3
     SyntaxError
    Explanation:
    Since all the operators present have the same precedence, calculations will be done left to right and the division results in float value


    Please send your answer here:



  • Top 100 Python Interview Questions
    What is the difference between a list and a tuple?
  • Answer
  • What is the difference between deep copy and shallow copy?
  • Answer
  • What is the difference between append and extend?
  • Answer
  • What is the difference between a function and a method?
  • Answer
  • What is the difference between sort and sorted?
  • Answer
  • What is the difference between an array and a list?
  • Answer
  • What is the difference between is and ==?
  • Answer
  • What is the difference arange and linspace?
  • Answer
  • What is the difference arange and range?
  • Answer
  • What is the difference args and kwargs?
  • Answer
  • What is the difference argument and parameter?
  • Answer
  • What is the difference between / and //?
  • Answer
  • What is the difference between break and continue?
  • Answer
  • What is the difference between break and pass?
  • Answer
  • What is the difference between list and set?
  • Answer
  • What is the difference between list and dictionary?
  • Answer
  • What is the difference between set and frozenset?
  • Answer
  • What is the difference between for loop and while loop?
  • Answer
  • What is the difference between datetime.now() and datetime.today()?
  • Answer
  • What is the difference between array and matrix?
  • Answer
  • What is the difference between mutable and immutable?
  • Answer
  • What is the difference between pop and remove?
  • Answer
  • What is the difference between print and return?
  • Answer
  • What is the difference between map and filter?
  • Answer
  • What is the difference between append and insert?
  • Answer
  • What is the difference between bitwise and logical operators?
  • Answer
  • What is the difference between break and return?
  • Answer
  • What is the difference between del and pop?
  • Answer
  • What is the difference between error and exception?
  • Answer
  • What is the difference between sinle quotes, double quotes and triple quotes?
  • Answer
  • What is the difference between else and elif?
  • Answer
  • What is the difference between expression and statement?
  • Answer
  • What is the difference between find and index?
  • Answer
  • What is the difference between global and local variable?
  • Answer
  • What is the difference between global and nonlocal variable?
  • Answer
  • What is the difference between eval and exec?
  • Answer
  • What is the difference between keyword and identifier?
  • Answer
  • What is the difference between keyword and variable?
  • Answer
  • What is the difference between reverse and reversed?
  • Answer
  • What is the difference between quit and exit?
  • Answer
  • What is the difference between yield and return?
  • Answer
  • What is the difference between ravel( ) and flatten( ) and reshape( )?
  • Answer
  • What is the difference between queue and dequeue?
  • Answer
  • What is the difference between generator and iterator?
  • Answer
  • What is the difference between zip and map?
  • Answer
  • What would be the output of executing the following code:
    d, e, f = {}, dict(), dict(())
    d['one'] = 1.0; d['two'] = 2.0; d['three'] = 3.0
    e = dict([('two', 2/1), ('three', 3/1), ('one', 1/1)])
    f = dict(zip(['three', 'one', 'two'], [3, 1, 2]))
    print(d == e and e == f and d == f)
  • Answer
  • What would be the output of executing the following code:
    b = [['1'] * 2] * 3
    b[1][1] = 'O'
    print(b)
  • Answer
  • Which line of code should replace '# Replace this line' in the following code snippet to get the result: 7
    def f1(a=1,b=2,c=3): return a+b+c
    v = {"a":6, "c":-1}
    # Replace this line
  • Answer
  • What would be the output of executing the following code:
    c = 50 + 50
    print(c in [50, 100, 50.0, 100.0] == True)
  • Answer
  • What would be the output of executing the following code:
    a = {1,2,6,8}
    b = {2,3,5,8}
    print((a) - (b))
  • Answer
  • What would be the output of executing the following code:
    print(0.0 or 0)
  • Answer
  • What would be the output of executing the following code:
    lang = ['Julia', 'R', 'Python']
    src = 'Learned Julia, Python, and R'.split(' ', 3)
    print(any(i in lang for i in src))
  • Answer
  • What would be the output of executing the following code:
    d = map(lambda c: chr(ord(c) + 1), "Oxsgnm")
    print(''.join(d))
  • Answer
  • What would be the output of executing the following code:
    s = list(range(10,20)[:4])
    s[:]= 11
    print(s)
  • Answer
  • What would be the output of executing the following code:
    k = [(10,'ten'),(11,'eleven'),(12,'twelve')]
    k.sort(key=lambda k: k[1])
    print(k[0][1])
  • Answer
  • What would be the output of executing the following code:
    print(sorted([8,5,9,5,7], key=lambda x:0 if x==9 else x))
  • Answer
  • What would be the output of executing the following code:
    for i in zip([1, 2, 3], ['x', 'y']): print(i, end='')
  • Answer
  • What would be the output of executing the following code:
    s = 'Ape deer elk cow yak fox ape'
    w = s.lower().split()
    print(max(dict(list(zip(w,[w.count(p) for p in w])))))
  • Answer
  • What is the difference between library and module and package?
  • Answer
  • Which of the following code snippets, when executed, would NOT give the output [0]
  • Answer
  • What would be the output of executing the following code:
    t = [10, 13, 16]
    print(max(t, key=lambda x: x%5))
  • Answer
  • What would be the output of executing the following code:
    s = "-4" "\\-2"
    print(len(s))
  • Answer
  • What would be the output of executing the following code:
    s = [1, 2, 3, 4]
    s[-1 : -5] = ['a']
    print(s)
  • Answer
  • What would be the output of executing the following code:
    t = [1,2,3,4]
    x = (t.pop() > t.pop()) > (t.pop() < t.pop())
    t.append(x)
    print(t)
  • Answer
  • What would be the output of executing the following code:
    w = [1, 2, 3, 4]
    w[2::-2] = [7, 8]
    print(w[0])
  • Answer
  • What would be the output of executing the following code:
    sum = 0
    for i in range(5, 0, -2): sum += i > sum
    print(sum)
  • Answer
  • What would be the output of executing the following code:
    a = ['xyz']
    b = ['p', 'q', 'r']
    print(list(zip(b, a)))
  • Answer
  • What would be the output of executing the following code:
    s = 'apple'
    print(s.find('p') + s.rfind('f') + s.find(''))
  • Answer
  • What would be the output of executing the following code:
    s = 'the smart owl'
    print(s[-9:-100:-2])
  • Answer
  • What would be the output of executing the following code:
    w = 'Python Rocks'
    print(w.find('Python') == False)
  • Answer
  • Which line of code should replace '# Replace this line' in the following code snippet to get the result: P-y-t-h-o-n!
    w = 'Python'
    d = {'sep':'-', 'end':'!'}
    # Replace this line
  • Answer
  • Which of the following code snippets, when executed would NOT give the following output:
    [1, 2, 3, []]
  • Answer
  • What would be the output of executing the following code:
    p = [0, 1, 2, 3, 2, 4]
    q = [4, 3, 2, 1, 1, 3]
    print(set(p) > set(q))
  • Answer
  • What would be the output of executing the following code:
    t = 'Hello Python'
    for i in range(5): t = tuple(t)
    print(len(t))
  • Answer
  • What would be the output of executing the following code:
    x,y = (False, False)
    if (y,) and [y,]: x+=1
    print(x)
  • Answer
  • What would be the output of executing the following code:
    y = zip(*[iter(range(7))]*3)
    print(list(y))
  • Answer
  • What would be the output of executing the following code:
    print(divmod(7, 3))
  • Answer
  • What would be the output of executing the following code:
    def f1(*num): print (num + num)
    f1(4/2)
  • Answer
  • What would be the output of executing the following code:
    k = ('Python' 'Rocks')
    print(k)
  • Answer
  • What would be the output of executing the following code:
    s1 = 'ppy!'
    f1 = 'a'.join(list(s1))
    print(f1)
  • Answer
  • What would be the output of executing the following code:
    list1 = ['Hi', 'python']
    len(list1.extend(list(range(3))))
  • Answer
  • What would be the output of executing the following code:
    import numpy as np
    s=j=k=0
    for e in np.eye(4)*5:s+=e[j];e+=1;j+=1
    print(s)
  • Answer
  • In python 3.8 or later, what would be the output of executing the following code:
    run = 20/2
    [run := run + x for x in range(10)]
    print(run)
  • Answer
  • Which of the following code snippets, when executed, would print True
  • Answer
  • What would be the output of executing the following code:
    a = [1, 2, 3, 4, 5, 6, 7, 8]
    print(a[-4:--1:-1])
  • Answer
  • What would be the output of executing the following code:
    print(2**3**2**0*2)
  • Answer
  • What is the difference between datetime.now( ) and datetime.today( ) methods?
    from datetime import datetime
    print(datetime.today())
    print(datetime.now())
  • Answer
  • What would be the output of executing the following code:
    a = [1.0, 2, 1, 2, 1.0, 2.5]
    print(a.index(1.0, 1))
  • Answer
  • In python 3.8 two dictionaries, d1 and d2, were created - d1 = {'p': 1, 'q': 2}; d2 = {'q': 3, 'r': 4}. Which of the following code snippet would NOT merge d1 and d2 into a new dictionary, d3, that will have {'q': 2, 'r': 4, 'p': 1} as its data.
  • Answer
  • k = 2
    s1 = 'a' * k
    s2 = "a" * k
    s3 = 'a' * 2
    s4 = "a" * 2
    After executing the code above, which of the following would print True
  • Answer
  • What would be the output of executing the following code:
    import re
    s = '@Raju will meets him @11 am or reply to hr@datai.co'
    print(re.findall('\S+@\S+[.]\w{2,3}', s))
  • Answer
  • Given two lists, a = [1, 2, 3]; b = [2, 3, 4], which of the following code snippets will NOT find the difference between the two lists (elements that are unique ie. elements that are present in one list, but not in the other)?
  • Answer
  • What would be the output of executing the following code:
    curr_rate, curr_state = 0, True
    print (not(curr_rate) + curr_state)
  • Answer
  • What would be the output of executing the following code:
  • Answer
  • What would be the output of executing the following code:
    print([n for n in range(1895, 1905) if (not(bool(n%4)) \
    and (bool(n%100) or not bool(n%400)))])
  • Answer
  • What would be the output of executing the following code:
    a, *b, c = (1, 2, 3, 4, 5)
    print(b)
  • Answer
  • Which of the following code snippets, when executed, prints the calendar of January 2021?
  • Answer
  • What would be the output of executing the following code:
    call_codes = {"France":33, "Brazil": 55, "UK": 44}
    sorted(call_codes)
  • Answer
  • Which of the following python statements, when executed, will NOT give the output 0.3
  • Answer
  • What would be the output of executing the following code:
    s1 = ['W', 'lo','Python']
    s2 = ['!', 've', 'e']
    print(" ".join(["".join([i, j]) for i, j in zip(s1, s2[::-1])]))
  • Answer
  • Which of the following code snippets, when executed, will give the time elapsed in seconds since the epoch as a float?
  • Answer
  • What would be the output of executing the following code:
    list1 = [True, 1, 0, True, 2, 1, False, 5, 0]
    print(sorted(list1))
  • Answer
  • Which of the following code snippets, when executed, will NOT give the output
    [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
  • Answer
  • Which of the following code snippets, when executed, will NOT give the output
    ['Hello', 'World']
  • Answer
  • What would be the output of executing the following code:
  • Answer
  • What would be the output of executing the following code:
    str1 = 'a quick red fox'
    str1[-2::str1.count('k')]
  • Answer
  • Which of the following statements, when executed, raises the TypeError?
  • Answer
  • What would be the output of executing the following code:
    "USA's $100b-plan q&a on WhatsApp".title()
  • Answer
  • What would be the output of executing the following code:
    x = [2, 1, 5, 6, 8, 9, 4]
    [sum(x[i::2]) for i in range(len(x)//(len(x)//2))]
  • Answer
  • Which of the following statements, when executed, raises the TypeError?
  • Answer
  • What would be the output of executing the following code:
    x, y, z = 2, 2, 2.0
    print((x is y) == (y is z), (x == z) is (y == z))
  • Answer
  • What would be the output of executing the following code:
    vowel_set = {'a', 'e', 'i','o', 'u'}
    all_vowels_set = vowel_set.add('A')
    print(all_vowels_set)
  • Answer
  • What would be the output of executing the following code:
    str1 = "python was born in the usa"
    print (str1.capitalize())
  • Answer
  • Which of the following will NOT create an empty dictionary?
  • Answer
  • Which of the following statements give the output True?
  • Answer
  • Which of the following statements about a frozenset is NOT true?
  • Answer
  • What would be the output of executing the following code:
    my_list = [1, 2, 3, 2, 4, 2, 1, 2]
    print(max(set(my_list),key=my_list.count))
  • Answer
  • Which of the following is NOT a way to shallow copy a list?
  • Answer
  • What would be the output of executing the following code:
    my_scores = (4, 6, 7, 9, 5, 4)
    my_scores.sort()
  • Answer
  • What would be the output of executing the following code:
    original_list = [1, 2, 3, 4]
    new_list = original_list
    new_list[1] = 8
    print(original_list)
  • Answer
  • What would be the output of executing the following code:
    list(range(5, 0, -1))
  • Answer
  • What would be the output of executing the following code:
    my_obj = 1, "hello", 4.5, [6,8], (8, 9.2)
    type(my_obj)
  • Answer
  • Which of the following is correct about the differences between a list and a tuple?
  • Answer
  • Which of the following about dictionary keys in NOT correct?
  • Answer
  • What would be the output of executing the following code:
    a, b, c = (1, 2, 3, 4, 5, 6, 7, 8)[1:6:2]
    print(b)
  • Answer
  • What would be the output of executing the following code:
    import numpy as np
    print(np.array((3, 4, 10.0, 4)))
  • Answer
  • What would be the output of executing the following code:
    print(sorted('Data Science')[2])
  • Answer
  • Which of the following is a keyword in python?
  • Answer
  • What would be the output of executing the following code?
    my_list = [3, 4, 7, 9.6, 8, 4]
    my_set = set(my_list)
    print(my_set)
  • Answer
  • What would be the output of executing the following code?
    olympic_venues = ['Beijing', 'London', 'Rio', 'Tokyo', 'Paris', 'LA']
    print(olympic_venues[1:-1:2])
  • Answer
  • Which the following functions can be used to convert an ndarray to a one-dimension array?
  • Answer
  • Which the following modules provides regular-expression functionality?
  • Answer
  • What is the output of executing the following code snippet:
    my_list = [2,3,4,5,6,4]
    my_list.remove(4)
    print(my_list)
  • Answer
  • What is the output of executing the following code snippet:
    poll_data = 7,
    type(poll_data)
  • Answer
  • What is the output of executing the following code snippet:
    salary = 36,567.90
    type(salary)
  • Answer
  • What is the output of executing the statement:
    [ ] and 5
  • Answer
  • What is the output of executing the statement:
    len(list("Hi Python!"))
  • Answer
  • What is the return value of print()?
  • Answer
  • Which of the following can be used as a dictionary key?
  • Answer
  • What would be output of executing this code:
    print(True*2)
  • Answer
  • Which code snippet will give this output:
    ['H', 'e', 'l', 'l', 'o']
  • Answer
  • Which of the following python statements will not be ignored by python interpreter, but the interpreter does nothing at run time as the intended use of the statement is to act as a stand-in or placeholder inside a class or function definition?
  • Answer
  • Which of the following built-in function of python will return the physical memory address of the object being referenced?
  • Answer
  • Which of the following is not supported by python?
  • Answer
  • Which of the following python objects is immutable?
  • Answer
  • Which code snippet will give this output:
    1.0 // 2
  • Answer
  • Which open source framework for parallel and distributed Python can make numeric computations many times faster?
  • Answer
  • What would be the output of executing the following code:
    print(round(7.5) - round(6.5))
  • Answer
datai analytics