Signup/Sign In

Basics of Core Java

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q. In a language processing application,a developer was working,on the following code:

import nltk

from nltk.stem import WordNetLemmatizer

lemmatizer=WordNetLemmatizer()

nltk.download('wordnet')

print(lemmatizer.lemmatize('foci'))
print(lemmatizer.lemmatize('criteria'))
print(lemmatizer.lemmatize('crises'))
        
What is the output expected?
Q. Below are a few points mentioned, about the internal working of an interpreter:
1) The __________ breaks the line of code into tokens
2) The __________ uses the tokens,to prepare a structure,that shows,relation between tokens.
3) The __________ turns the token structure,in code objects.
4) The __________ runs the code objects.
Mark the correct option.
Q. In an interview,code snippets of some built-in functions,were given:

#1
print(sorted('ExaCtLy'))

#2
print(divmod(26,5))

#3
abc=44
print(eval('abc+44'))
    
Mark their correct output.
Q. A fresher,was given the task,of converting a few functions, in Python,to lambda expressions:

#1
import math

def cube_root(x):
    return math.pow(x,1/3)

#2
def add_three(x,y,z):
    return x+y+z


Mark the correct lambda expressions.

Q. In an exam,following code snippet was provided:

class Sum:
    def __init__(self,sum):
        self.sum = sum
class Number(Sum):
    def __init__(self,sum):
        self.value = sum*2
    def show(self):
        print(self.value,self.sum)
objsum = Number(8)
objsum.show()   

Mark the correct output of the same.
Q. In an interview,freshers were asked,to mark the following statements,as Valid or InValid:
1) The *args allows,zero number of extra arguments.
2) The *args and **kwargs, when used together, should be in the order:

def somefunc(fnargs,*args,**kwargs):
    Using **kwargs before *args,will throw an error.


3) **kwargs is used,to pass a keyworded,variable length argument list.
4) **kwargs can be compared,to a set object,such that,when we iterate over it,the elements are orderly printed.
Q.Below are a few statements made,either about xrange or range function:
1) A particular range, is shown on demand,hence,it is also called as "lazy evaluation".
2) It returns the list of numbers,created using the range() function.
3) Here,the variable,storing the range returned,takes more memory
4) Operations related to the 'list',cannot be applied,on an object here.
Mark them appropriately.
Q. In a technical competition, participants had to face a rapid fire round, about Python facts:
They were supposed to answer the questions as Yes or No.
1) Python does not have any data types, for characters,as they are treated as strings.
2) Try and catch, is used for exception handling.
3) A do-while loop,is present in Python.
4) Python is not a compiled language.
Mark the correct output.
Q. A developer was working,with the 'numpy' library,for performing some mathematical operations. Consider the following code snippet-

import numpy as np 

array1 = np.arange(12)
array2 = array1[3:11:4] 

print(array2)

array3=np.array([[34,45,23],[56,67,22],[66,89,90]])

print(array3[...,1])
    
    

Mark the correct answer.

Q. In an exam,following code snippets were provided:

#1

from collections import Counter
cake=Counter({'vanilla':43,'chocolate':12,'coffee':23})
print(cake['d'])

#2

from collections import Counter
eg1=Counter('test')
eg2=Counter('text')
print(eg1+eg2)

    

Related Tests: