Python Online Practice Test - 13

This Test will cover complete Python with very important questions, starting off from basics to advanced level.
Q. In an interview, following code snippet was provided:
first, second, third = 'red', 'blue', 'green'
first, second, third = second, third, first
complexa, complexb = 1+4j, 4+3j
print(first)
print(third)
print(second)
print(complexa + complexb)
Mark the correct print outputs.
Q. In a competition, following statements were given and Developers were told to mark the False one out of these statements:
Q. A group of developers,were involved in a debate about the features of Java and Python. Following points were raised:

Dev A: The Python interpreter works more at runtime since it finds the type of variables at that time. Since Java is statically typed, this effort is saved. Still, overall Java is slower than Python, as it contains more lines of code. Java should only be used in critical database applications.

Dev B: Java is faster than Python. So in projects, where speed is the issue, we should choose Java. Python is more portable than Java.

Dev C: In critical database applications, Python should be used, as its database access layer, is more stronger than JDBC. Projects where speed is an issue Python should be used, as its code is always smaller than Java.

Mark the correct choice.

Q. A developer was teaching her peer, about negative indices in Python. After explaining the concept, she gave him a test question:
study_program = [23,56,76,89,93]
print(study_program[-4])
print(study_program[-5:-2])
print(study_program[-3:-4])

Choose the correct answer.

Q. A developer was asked to unpack tuple values into some variables. He was confused about doing the same so he consulted his peers. The tuple given was:
tuple_port = ("Pipavav", 1212, "Gujarat")

Mark the correct syntax.

Q. A developer was asked to explain the benefits of using Django for a clients travel web application. He was given a list of following points:
  1. It provides an auto-generated web admin.
  2. Since no pre-packaged API are present, development is easy.
  3. It allows to define a URL for a given function.
  4. It avoids code duplication, by allowing to define a HTML template, for a web page.
  5. It enables separation of business code from HTML.

Mark the correct output of the same.

Q. Given are a few statements regarding migrations in Django:
  1. Commands makemigrations and migrate can run in any order. It does not matter.
  2. makemigrations command, generates, SQL commands to create table based on the classes defined in the models.py file.
  3. Correct command for running makemigrations is - python database.py makemigrations and for migrate is - python manage.py migrate.
  4. makemigrations command creates tables of preinstalled apps. migrate command creates table for newly created apps.

Mark if they are True or False.

Q. Consider the following code snippets -
book1 = {'nancy drew',12,1980} 
book1.add('nancy drew')
print(book1)
book2 = {23,34,{'hardy boys'}}
print(book2)
book3 = {['famous five'],56,67}
print(book3)

Mark the correct output of the above.

Q. Consider a few statements regarding Modules and Packages:
  1. The module_name.reload() function allows us to reload the module as required.
  2. Both a module and package, must contain _init_.py file.
  3. Package is a directory,containing subpackages and modules
  4. When a package is imported, its immediate subpackages and modules, get imported.

Mark them as Correct(C) or Incorrect(In).

Q. Below mentioned, are a few descriptions of the functions present in the Python OS module:
  1. Returns the current working directory of a process.
  2. Creates a hard link that points to a source(src) called dst.
  3. Creates a raw device number, by taking the minor and major device numbers, as arguments.

Map the above with the function name.