python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 7, Interview Questions Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Guido van Rossum

Python Interview Questions and Answers

What Is Python?
Python is an Interpreted, Interactive, Object-Oriented, and high level programming language and it has design philosophy that emphasizes code readability.

Python is created by Guido van Rossum and the first released in 20 February 1991; around 26 years ago.
Python features a dynamic type system and memory management automatically. It also supports multiple programming paradigms like –
ü  Object Oriented
ü  Functional
ü  Procedural
ü  Imperative
ü  Comprehensive standard library

What Are the benefits of Python?
The benefits of Python are –
ü  simple
ü  easy,
ü  portable,
ü  extensible,
ü  build-in data structure
ü  open source
ü  and so on

What Are the key features of Python?
Some great features of Python are -
ü  Python supports OOPs
ü  Python supports a style of programming called functional programming.
ü  Python supports structured programming methods
ü  Python used scripting language
ü  Python provides very high-level dynamic data types
ü  Python supports dynamic type checking
ü  Python supports garbage collection
ü  Python is interpreted languages so don’t need to be compiled before it is run like other (Ruby, PHP) interpreted languages.
ü  Writing code is very quickly.
ü  Python easily integrated with other programming languages like - C, C++, COM and Java.

Is Python Object Oriented?
Yes! Python is an object oriented programming.

Is Python a Case Sensitive Language?
Yes! Python is a case sensitive programming language.

How Python is interpreted?
As you know, Python is an interpreted language and its program runs directly from the source code and the source code converts into an intermediate language. The intermediate language converts into machine language that has to be executed.

Which Python library is used for Machine Learning?
The Python growing adoption in data science and For Machine Learning Python used to SciKit-Learn library.

What Is Namespace in Python?
In Python programming, all name introduced has a place where it lives and can be hooked for that is called namespace.

How to overload constructors or methods in Python?
The Python constructor – _init__ () is a first method of a class. When you try to instantiate an object __init__() is automatically invoked by Python to initialize members of an object.

How Are the differences in help () and dir () functions?
The help () function - This function is used to display the documentation string and also helps for related to modules, keywords, attributes.
The dir () function - This function is used to display the defined symbols. It's only display the defined symbols.

What Are the differences in deep and shallow copy?
The shallow copy - This function is used when a new instance type gets created and also keeps the values that are copied in the new instance.
The Deep copy - This function is used to store the values that are already copied. It doesn’t copy the reference pointers to the objects.

What Are the differences in list and tuple?
The main difference is –
The list is mutable while tuple is not that means tuple is immutable.

How ternary operators be used in Python?
The Ternary operator is special kinds of operator which used to show the conditional statements and these conditional statements will return true or false.

What Are the supported data types in Python?
Python has five standard data types which are -
ü  Numbers
ü  String
ü  Tuple
ü  List
ü  Dictionary

What Is Tuples in Python? How differ with Lists?
The Tuple is another sequence data type and it’s similar to list.
The Tuples are enclosed in parentheses ( ( ) ) and their elements and size can’t be updated. Tuples can be thought of as read-only lists.
The Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed.

What Is built-in type in Python?
Python provides mutable and Immutable types -
The Mutable built-in types-
ü  List
ü  Dictionaries
ü  Sets
The Immutable built-in types -
ü  Strings
ü  Numbers
ü  Tuples

What Is lambda in Python?
In Python, lambda is an anonymous function that means a function that is defined without a name and it also known as single expression. The normal functions are defined using the def keyword.

In other world we can say that lambda is just a way of defining inline functions.
x = lambda a: a + 1
print x(1)

And
def x(a): return a + 1
print x(1)

How Is memory managed in Python?
Python used heap. The Python objects and data structures are located in a private heap and the developer’s doesn’t have the permission to access this heap because the heap is private mode.

Python supports garbage collector. As you know the garbage collection is manage the memory automatically. It checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

What Are the differences in Xrange and range?
The Xrange - the Xrange returns the Xrange object.
The range - the range returns the list.
Both Xrange and range are uses the same memory and no matter what is the range size.

What Are the local and global variables in Python?
The Local Variable -If a variable is assigned a new value anywhere within the function body that we assumed to be local variable.
The Global Variable - If a variable's referenced inside a function that we assumed to be global variable.

Which command you use to exit help window in Python?
The quit command is used to exit the window.

How will you get the length of the string?
We find the length using len(string) function and It will returns the length of the string.

How will you remove last object from a list?
For example –
MyList.pop(obj= MyList [-1])

The above line of code will remove and returns last object from list.

How will you remove an object from a list?
For example –
MyList.remove(obj)

The above lines of code will remove object obj from the list.

How will you reverse a list?
For example –
MyList.reverse()

The above lines of code will reverse objects of list in place.

How will you Sort a list?
For example –
MyList.sort([func])

The above lines of code will sorts objects of list and used to compare func if given.

Other example is –
list = ["2", "5", "0", "7", "10"]
list = [int(i) for i in list]
list.sort()
print (list)


What Is the zip() function in Python?
The zip () function is used to combine the multiple lists in a single list.
For example -
list_1 = ['x','y','z']
list_2 = [99,190,300].
zip(list_1, list_2)


The Results is –
[('x',99),('y',190),('z',300)]


Noted Point - Please keep in minds, whenever the given lists are of different lengths, the zip function stops generating tuples when the first list ends.

What Is pickling and unpickling?
The pickling module accepts any Python object and converts it into a string using dump function.
The unpickling module accepts any Python object and converts into a file using dump function.
This process is called pickling and these processes retrieving the original objects from the converted string is called unpickling.

What Is a Python module?
Python module is a script that contains import statements, variable, functions and classes.
Python module can be imported by other modules and its way looks like -
ü  import
ü  from module-name import

How to open a text file and display its contents?
The best way to open a text file by using the “with” command -
with open("YourfileName", "r") as pf:
readFile = pf.read()

#to print the contents of the file print(readFile)


How to get a random number in Python?
The random () method is used to returns a random float R, such that 0 is less than or equal to R and R is less than 1.

What Is split(), sub(), subn() functions?
The split() function – The function is uses a regex pattern to “split” a given string into a list.

The sub() function – This function is used to finds all substrings where the regex pattern matches and then replace them with a different string.

The subn() function – This function is very similar to sub() and it also returns the new string along with the number of replacements. 
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions