DronaBlog

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.








            



No comments:

Post a Comment

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

What is CRM system?

  In the digital age, where customer-centricity reigns supreme, businesses are increasingly turning to advanced technologies to manage and n...