DronaBlog

Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

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.






                                      



Thursday, December 13, 2018

What are the features of Python Programming

Are you interested to know what are the features of the Python language? Would you like to start programming in Python and would be interested in knowing more about Python? If so, then you reached the right place. This article provides detailed information about the advantages of Python Programming.

Python Advantages:

  • Easy to learn
  • Object Oriented Programm
  • Portable (Cross-platform)
  • Expressive (Understandable and Readable)
  • Interpreted
  • GUI Programming
  • Free and Open source

1. Easy to learn:

Python is easy to learn compared to other programming languages such as Java, .NET or C++.  Python programming syntax is simple and easy to read and write. The concepts such as function, structures, expression can be easily understood by the beginner with ease. No exhaustive list of software is required to learn and work on Python programming. A simple editor such as notepad or development IDE such as PyCharm is enough to start with Python. If you are first time learning any programming language then Python is the best language to start with. Along with its simplicity, Python is also a very strong and robust language which can be used to developing enterprise applications.

2. Object Oriented Programming

Python is Object Oriented language. i.e. all features of Object Oriented programming such as inheritance, polymorphism, abstraction, and polymorphism are supported in Python. In Python class acts as the blueprint and it will be model for the objects. Every real-time entity such as human being, trees, non-living things can be represented as the object.
e.g. In the example below, the class for 'Cat' is presented using Python language.

class Cat:

    def __init__(self, cat_name, cat_age):  
        self.cat_name cat_name
        self.cat_age cat_age



3. Portable (Cross-Platform)

Python is a portable language. It is also known as cross-platform language. It means we can run the same program on different Operating Systems such as Windows or Mac or Unix as long as we have Python interpreter installed on these operating systems. We do not need to write program specific to any operating system. However, we need to keep in mind that there are some features which are dependent on the Operating System. Such features need to be handled properly if your program is going to run on multiple systems. 

4. Understandable and Readable

The breadth of ideas that can be represented and communicated using the Python language is quite better than other programming languages. There are some features in the Python language using which we can build the business functionalities extensively. These extensive features may not feasible in other languages. Programming in the Python language is easily understandable and readable which help us to build better and extensive programming functionalities. Hence, the Python language is expressive and it is one of the great features.

5. Interpreted language

Python is interpreted language. The source code in Python is executed line by line, unlike Java language where the complete code is compiled first and then it is executed. Python using an interpreter to interpret Python code. The interpreter converts Python source code to bytecode which operating system can understand and execute step by step.



6. GUI Programming

Python provides GUI programming framework by using which we can develop user interfaces. The framework TkInter can be used to build the user interface for Python. 

7. Free and Open Source

Python software is open source and it is freely available. No additional cost is required for the licensing. Python software and custom modules are freely available for download over the internet. The Python module communities provide a good number of Python useful utilities in the form of Python modules.




The video below provides detailed information about Python language -







Friday, December 7, 2018

Important Python Interview Questions and Answers - Part III

Are you preparing for Python interview and looking for questions and answers? Would you also like learn Python concepts? If so, then read this article to prepare for your interview. If you have not read the previous article  then you can read here Important Python Interview Questions and Answers - Part II


Q 1: What is the use of PYTHONPATH environment variable in Python language?

Answer
  • The environment variables PATH and PYTHONPATH are similar. 
  • The variable PYTHONPATH provides information to Python interpreter in order to locate the module files or source code files which are imported in the source code.
  • Normally, PYTHONPATH includes source library directory and the directories which contain source code. 
  • The Python installer normally setup PYTHONPATH variable automatically. If it is not set then we have to manually set it.

Q 2: Explain the purpose of PYTHONCASEOK and PYTHONSTARTUP environment variable in Python?

Answer: The environment variables such as PYTHONCASEOK and PYTHONSTARTUP are important for Python programming and execution as like PYTHONPATH variable. 
  • PYTHONSTARTUP:
  1. This variable contains path of an initialization file containing Python source code.
  2. When we start the Python interpreter, initialization is executed each time.
  3. In the Unix system, it is named as pythonrc.py
  4. The commands are included to load utilities or change PYTHONPATH  
  • PYTHONCASEOK:
  1. It is used in the Windows operating system.
  2. It is used to find the first case-insensitive match in the import statement.
  3. To activate this variable, we can set it to any value.
  • PYTHONHOME:
  1. It is normally used within PYTHONSTARTUP or PYTHONPATH directories.
  2. It is used to make easines in switching module libraries. 


Q 3: How to convert a String value to an integer, a long and a float value in Python?

Answer: Converting String to other data types such as integer, long and float is common practice in Python programming. It is required for the various reason such as to perform arithmetic operations.
1. String to Int -
Use int function to convert the String value to an integer.
Syntax: Here, base specifies the base if x is a string.
int(x [,base])  
Example:
x = "5"
int_value = int(x) 
2. String to long -
Use long function to convert the String value to the long value.
Syntax: Here, base specifies the base if x is a string.
long(x [,base])  
Example:
x = "50000"
long_value = long(x) 
3. String to Float -
Use float function to convert the String value to the float value.
Syntax: Here, base specifies the base if x is a string.
float(x)  
Example:
x = "8.5"
float_value = float(x)

Q 4: What is the use of ** operator Python language?

Answer:  
  • It is an arithmetic operation. 
  • It is known as the Exponent operator.
  • It is used to perform an exponential i.e. Power calculation
e.g.  a = 4  and b = 5
       a **  b =  1024




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

Answer:

  • The operator // is called floor division
  • It is the division of operands where the result is the quotient in which the digits after the decimal point are removed.








            



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))





                                        


Tuesday, December 4, 2018

Important Python Interview Questions and Answers - Part I


In this article, we will focus on the most important questions which are asked during Python interviews. If you preparing for Python interview then this article will be the good start. If any detailed explanation is required then respective links are provided for your knowledge. Good luck with your interview.



Q1. What are the differences between Python version 3 and Python Version 2?

Answer: Both the Python versions are important for Python programming and they come with their own significance. We will discuss here the differences between these two Python versions.

S. No
Python Version 3
Python Version 2
1.
Python version 3 supports -Unicode UTF-8 and it has two-byte classes –a) Byte b)ByteArray
Python version 2 supports - ASCII str() types and separate Unicode() but there is no byte type code
2.
To print, any string parentheses are required in Python version 3. It will raise error without parentheses.
In Python version 2, to print any string no parentheses are required
3.
If we try to compare un-orderable types then it raises ‘TypeError’ as the warning
Python version 2 silently ignore the error/warning we try to compare un-orderable types
4.
The SyntaxError will be reported when we don’t enclose the exception argument in parentheses.
In this version, it accepts both new and old notations of syntax.



You can refer the video tutorial on Python to better understand Python concepts -


Q 2: What is the memory management process in Python?

Answer: The memory management in Python is similar to other programming languages such as Java.
  • The allocation of heap space is done by the memory manager. It includes memory allocation for Python objects and data structures.
  • The private heap space is used in Python for memory management. The data structures and Python objects are located in this private heap memory. 
  • The Python interpreter interacts with memory and takes care of memory-related tasks.
  • The garbage collector is used to release memory of unused object and make memory available to the heap space. The garbage collector is the inbuilt feature, no special configuration is not required.

Q 3: How Python is interpreted?

Answer: 
  • Python language is an interpreted language. 
  • The program written by the developer is interpreted by Python interpreter. 
  • Once the source is interpreted, it is executed step by step. 
  • The Python program runs directly from the source code, unlike Java compiler where the complete file is compiled first and then it is executed.
In the figure below, HelloWorld.py a Python file is interpreted by Python interpreter and executed at runtime. The output is shown on the console.

Q 4: What is namespace in Python language?

Answer: 
  • The namespace in Python defines the scope for objects such as package, module, class, function.
  • Each module, package, class, and function owns a namespace. In this namespace, variable names are resolved.
  • The namespace is evaluated during execution and dropped after execution is completed.
  • The global namespace is used if the local namespace is not defined.
  • The variable name is checked in the local namespace i.e. in the body of the function or the module, etc. If the variable name is not found in a local namespace then it is checked in the global namespace.
  • The variables are generally created in a local namespace. 



Q 5: What are the module and the package in Python language?

Answer: 
a) Module: The module is the way to structure program. The module can contain one more many Python program file or files. The module can import other modules like the attributes and the objects.

b) Package:  The package is the folder in Python language. A package can have modules or subfolders.








What are differences between multimerge and merge API in Informatica MDM

                Are you interested in knowing what is the use of multimerge and merge APIs? Are you also would like to know the difference b...