Net-informations.com
SiteMap  | About    

Python Interview Questions FAQ - 1

Please click on the questions to see the answers

Python actually got its name from a BBC comedy series from the seventies "Monty Python's Flying Circus". The designer needed a name that was short, unique, and slightly mysterious. Since he was a fan of the show he thought this name was great, so he decided to call the language Python.

There are various web frameworks provided by Python. Some popular frameworks are :

  1. Django
  2. TurboGears
  3. Web2py
  4. Flask
  5. Pyramid
  6. Cubic Web

Pep8 is a coding standard and Style Guide for readability and long-term maintainability. It was designed to help python developers write more readable code. It's not a requirement for your code to work, just a good coding practice you should follow.

There are various IDE for Python development. Some popular IDEs are :

  1. Pycharm IDE
  2. Pydev IDE
  3. Wing IDE
  4. Eric Python IDE
  5. Vim IDE
  6. IPython Notebook
Also, Visual Studio has an extension for Python: https://pytools.codeplex.com

Python is a platform independent language, it works for all Operating Systems like, Windows, Unix, Linus, MacOS etc.

Yes, Python a case sensitive language Case sensitive means that x is different from X. The variable of John is different from the variable of john.

Setting the PYTHONPATH environment variable is an easy way to make Python modules available for import from any directory. When you import modules in python, python searches for the module in the directories in PYTHONPATH, in addition to some other directories.

Documentation is important to understand what the code does. Docstrings are for people who are going to be using your code without needing or wanting to know how it works. Docstrings can be turned into actual documentation. While, comments are meant to give specific information on blocks or lines, #TODO is used to remind you what you want to do in future, definition of variables and so on.

Importing * from a module, you will import all the functions and classes in your own namespace, which may clash with the functions you define yourself. Also you don't know exactly what is imported and can't find place from what module certain thing was imported easily (readability).

In Python 2.x print is actually a special statement, while in Python 3.x the print statement has been replaced with a print() function. It means that we have to wrap the object that we want to print in parentheses. Python 2 doesn't have a problem with additional parentheses, but in contrast, Python 3 would raise a Syntax Error if we called the print function without the parentheses.

The input()method in Python return strings. Convert the result to integer explicitly with int()/float().

Python's data types are built in the core of the language. Sticking to the hierarchy scheme used in the official Python documentation these are numeric types, sequences, sets and mappings.

Numeric types: int, long, float, complex.

Sequences: String, bytes, byte array, list, tuple.

Sets: set, frozen set.

Mappings: dict.

A decorator is a function that takes another function and extends the behaviour of the latter function without explicitly modifying it. This supports more readable applications of the DecoratorPattern but also other uses as well.

No. There is no switch or case in Python.

On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user's home directory.

or

"//" is for flooring division

The "in" operator you can use in this case.

Above statement validate... x=1 or x=2 or x=3 or x=4 or x=5.

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. The subprocess.call() method run the command described by args. Wait for command to complete, then return the returncode attribute.

Windows example

Unix example

_abc: weak "internal use" indicator. E.g. from X import * does not import objects whose name starts with single underscore.

__abc: the interpreter replaces this name with _classname__abc as a way to ensure that the name will not overlap with a similar name in another class.

Python does not have that restriction of single quotes for chars and double quotes for strings. Both are equal and what you use is entirely your preference.

In Python 2, raw_input() takes exactly what the user typed and passes it back as a string.

In Python 3, raw_input() was renamed to input() so now input() returns the exact string and Old input() was removed.

In python 2.x range() returns a list and xrange() returns an xrange object, which is kind of like an iterator and generates the numbers on demand. In Python 3, there is no xrange() , but the range() function behaves like xrange in Python 2. If you want to write code that will run on both Python 2 and Python 3, you should use range().

output

To leave the interactive shell and go back to the console (the system shell), press Ctrl-Z and then Enter on Windows, or Ctrl-D on OS X or Linux. Alternatively, you could also run the python command exit()!

In python we can Both positive and negative index . Negative index is used in python to index starting from the last element of the list, tuple or any other container class which supports indexing.

-1 refers to the last index, -2 refers to the second last index and so on.

output

Yes. Python is an object-oriented language, in which the program is built around objects which combine data and functionality. Python classes provide all the standard features of Object Oriented Programming. It is a mixture of the class mechanisms found in C++ and Modula-3.

Python is an object-oriented language but not pure. Python doesn't support strong encapsulation, which is only one of many features associated with the term "object-oriented".

Python Object is simply a collection of data (variables) and methods (functions) that act on those data. And, class is a blueprint for the object. Here is a simple class definition.

Python int() method is the standard built-in function to convert a string into an integer value. You call it with a string containing a number as the argument, and it returns the number converted to an actual integer.

It will print 'Hello World!' two times.

The .title() method of a string (either ASCII or Unicode is fine) will capitalize the first letter of each word in a string.

The method isalnum() checks whether the string consists of alphanumeric characters.

Python str.isdigit() method return true if all characters in the string are digits and there is at least one character, false otherwise.

You can use the strip() to trim whitespace in Python.









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.