DronaBlog

Wednesday, December 5, 2018

Important Python Interview Questions and Answers - Part II



In this article, we will see details on the most important questions which are asked during Python interviews. In the Python interview question and answers part - , we learned some basic questions. In this article, we learn more interesting questions and their answers in order to prepare for the Python interview. Good luck with your interview.



Q 1: What are the differences between List and Tuples?

Answer: The mentioned below is list differences between List and Tuples

List
Tuples
List elements can be changed as they are mutable
Tuples elements cannot be modified as they are immutable.
Normally, lists are slower compared to tuples during execution
Normally, tuples are faster than lists during execution of the program.
The list is created using open and close rectangular brackets
Tuples are created using open and close simple brackets
e.g. country_list = [“US”, “INDIA”, “UK”]
e.g. region_tuple = (“NA”, “APAC”, “LA”)


Q 2: Explain Multithreading concepts in Python?

Answer: The multithreading in Python is explained as below
  1. In order to achieve multithreading i.e. executing the program in parallel, Python has a multi-threading package.
  2. The concept named the Global Interpreter Lock (GIL) is used in Python.  It is the responsibility of GIL to make sure that only one ‘threads’ can execute at any a time. 
  3. The thread acquires GIL for processing business logic. Once processing is completed, it passes the GIL onto the next thread.
  4. This processing happens very quickly so to the human eye. On the surface, it looks like threads are running in parallel, but they are really just taking turns using the same CPU core.
  5. The extra overhead of working with GIL will cause extra processing time.



Q 3: What are the rules or standards for global and local variables in the Python language?

Answer:  The basic guidelines for local and global variables are as below
Global variables: The variables which are only referenced inside a function are implicitly global.

Local variables: The local variables are those variables for which a new value is assigned within the function's body.

Q 4: What are the supported data types in Python?

Answer: The supported data types in Python are 
  1. Number
  2. String
  3. List
  4. Tuple
  5. Dictionary
Here, the Number data type can include integer and float values.

You can refer the video below to learn more about Python programming -

Q 5: Is it possible to convert Integer value to String value and vice-versa in the Python language?

Answer: Yes, we can convert an integer value into the String value. Also, we can convert the String value to integer value.  

Normally, if we get input from the user is comes as String even it is number. So in such cases, we need to convert the String value to an integer value  as

    user_input = input("Enter any number")
    int_value = int(user_input)
    print(int_value * 5)

In some cases, we need to convert the numeric value to String value. e.g. Printing number value with appending string content.

       int_age_value = 25
   print("Age of a person is " + str(int_age_value))





                                        


No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Dynatrace : An Overview

  Dynatrace, a leading provider of software intelligence, offers a powerful platform designed to monitor, analyze, and optimize the performa...