Q81. What is the purpose of pass in Python?

Ans: Suppose you are designing a new class with some methods that you don't want to implement, yet.

class MyClass(object):

    def meth_a(self):

        pass

    def meth_b(self):

        print "I'm meth_b"

 

If you would leave out the pass, the code wouldn't run. To summarize, the pass statement does nothing particular but can act as a placeholder.

However, there are many more usage but in short that is.

 

Q82. Which all are Python web scrapping libraries?

Ans : There are following Python web scrapping libraries are available

  • The Farm: Requests
  • The Stew: Beautiful Soup 4
  • The Salad: lxml
  • The Restaurant: Selenium
  • The Chef: Scrapy

 

Q83. What is the purpose of the with statement in Python?

Ans : In python the with keyword is used when working with unmanaged resources (like file streams). It allows you to ensure that a resource is "cleaned up" when the code that uses it finishes running, even if exceptions are thrown. It provides 'syntactic sugar' for try/finally blocks.

 

It’s handy when you have two related operations which you’d like to execute as a pair, with a block of code in between. The classic example is opening a file, manipulating the file, then closing it:

 with open('HadoopExam.txt', 'w') as f:

     f.write('Welcome to HadoopExam Learning Resources…')

The above with statement will automatically close the file after the nested block of code. (Continue reading to see exactly how the close occurs.) The advantage of using a with statement is that it is guaranteed to close the file no matter how the nested block exits. If an exception occurs before the end of the block, it will close the file before the exception is caught by an outer exception handler. If the nested block were to contain a return statement, or a continue or break statement, the with statement would automatically close the file in those cases, too.

 

Q84. What is the difference between {} dictionary and “OrderedDict”?

Ans: OrderedDict maintain the insertion order. In whatever order all the key value pairs are added to dictionary will be maintained and that cannot be possible with the regular dictionary.

 

Q85. Which is faster when we need to apply search operation on list and dictionary?

Ans : Dictionary will be faster than list, if you search based on the key.

 

Learn Python in Less than 8 Hours sitting at Home/@Desk

Why Dont you prepare for Python Certifications and Interview Questions with 250+ Questions and Answer : Check Here

Real Exam Number of Questions: 70 Questions
Real Exam Pass Score: 70%
Time Allotted: 90 minutes to complete exam