DronaBlog

Tuesday, December 18, 2018

Important Python Interview Questions and Answers - Part IV


Are you preparing for Python interview? Are you looking for information about data comparison and data modifier functions commonly used in Python language? Are you also interested to learn Python concepts? If yes, then refer to this article which is helpful for interview preparation as well for learning Python concepts. I would also recommend reading the previous article on Important Python Interview Questions and Answers - Part III

Q 1: What is Python?

Answer:
Python is a programming language with below features -
  • High-level
  • Interpreted
  • Interactive 
  • Object-oriented 
  • Used for Scripting
  • Highly readable. 
Python is simple in nature as it uses English keywords with fewer syntactical constructions.

Q 2: What is the Dictionary data type in the Python language?

Answer
  • The dictionary data type defines one-to-one relationship between keys and values. 
  • It contains the pair of keys and associated values
For example, 
region_country = {  
                               'NA':'CANADA',
                               'LA':'PERU',
                               'APAC':'INDIA'
                             }

In the example above, the region value such as NA, LA, and APAC are keys in the dictionary. The country values such as CANADA, PERU, and INDIA are values associated with keys in the dictionary.



Q 3: How to compare two lists with each other? Is there any way to determine the length of a list?

Answer:
A List or an Array in Python is data storing structure. Using a list we can store values during program execution. We can read, update or append values to the List structure. There are several utility functionalities comes with List. These functionalities are helpful during Python programming.

a) Assume that we have two lists as below:
country_list = ["US", "INDIA", "UK"]
region_list = ["NA", "LA", "APAC", "EMEA"]

We can compare elements of two lists by using cmp function as 

cmp(country_list , region_list )

b) The size or length of a list helps in many scenarios such as iterating over list value based on the size of the list. Python List comes with len function which gives the total length of the list.

len(country_list )






Q 4: How will you convert the String value to an Object, a Tuple and a List? How will you convert the object value to the String value?

Answer:
During programming for an application using any technology, we need to interact with many interfaces which work on different data types. There are some cases we need to manipulate data which requires different data type. So converting the String to other data type is not an exception for it. So Python provides the function to achieve it.

a) Convert an object to a String
Use str function to convert an object value to the String value as 
str(x) 

b) Convert a String to an object
Use eval function to convert the String value to an Object value as 
eval(str) 

c) Convert a string to a tuple
Use tuple function to convert the String value to the Tuple as 
tuple(s)

d) Convert a string to a list
Use list function to convert the String value to the List as 
list(s) 

Q 5: What is the use of 'is' operator in Python language?

Answer:
The operator 'is' is used to evaluate
a) To true if the variables on either side of the operator are the same object 
b)To false if the variables on either side of the operator are the different object  

e.g. x is y

Here, 'is' results in 1 if  object (x) equals object (y).




In order to learn the Python language, you need to install PyCharm tool. The video below explains how to install PyCharm Tool.






                                      



No comments:

Post a Comment

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

Understanding Survivorship in Informatica IDMC - Customer 360 SaaS

  In Informatica IDMC - Customer 360 SaaS, survivorship is a critical concept that determines which data from multiple sources should be ret...