Python Questions
What is output of following code?
x = (5, 7)
x[0] +=3
x = (5, 7)
x[0] +=3
✅ Answer ✅
TypeError − ‘tuple’ object does not support item assignment because a tuple is immutable.
TypeError − ‘tuple’ object does not support item assignment because a tuple is immutable.
def foo(x = 10, y = 15):
return(x + y, x - y)
x, y = foo(y = 20, x = 15) print(x, y) #What is the output of the following code?
return(x + y, x - y)
x, y = foo(y = 20, x = 15) print(x, y) #What is the output of the following code?
Anonymous Quiz
33%
Error - arguments order
49%
35 -5
13%
35 30
5%
30 30
Which is the correct way to create an empty set in Python?
Anonymous Quiz
20%
[..]
25%
set[..]
14%
(..)
40%
set(..)
Consider the following sequence of statements:
n = 300
m = n Following execution of these statements, Python has created how many objects and how many references?
n = 300
m = n Following execution of these statements, Python has created how many objects and how many references?
Anonymous Quiz
19%
Two objects, two references
35%
One object, two references
29%
Two objects, one reference
17%
One object, one reference
What Python built-in function returns the unique number assigned to an object:
Anonymous Quiz
13%
refnum()
24%
identity()
50%
id()
13%
ref()
Which of the following styles does PEP8 recommend for multi-word variable names
Anonymous Quiz
29%
DistanceToNearestTown (Pascal Case)
36%
distanceToNearestTown (Camel Case)
35%
distance_to_nearest_town (Snake Case)
Which of the following are Python reserved words (keywords). Select all that is correct.
Anonymous Poll
50%
default
57%
None
68%
class
58%
and
32%
goto
employeenumber = 4398
EmployeeNumber = 4398
employeeNumber = 4398 # You are reading Python code, and these statements appear scattered in different locations throughout the code:
EmployeeNumber = 4398
employeeNumber = 4398 # You are reading Python code, and these statements appear scattered in different locations throughout the code:
Anonymous Quiz
34%
These statements refer to the same variable.
66%
These statements refer to different variables.
What type of value will result from evaluating the following expression:
(' ', )
(' ', )
Anonymous Quiz
30%
str (string)
37%
tuple
8%
dict
16%
syntax error
11%
unicode (unicode string)
Which of the following function convert a string to a float in python?
Anonymous Quiz
17%
toFloat(x)
75%
float(x)
5%
decimal(x)
3%
long(x [,base] )
#interviewQuestions : 0001
What is Python?
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics, automatic memory management.
What is Python?
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics, automatic memory management.
#interviewQuestions : 0002
Explain the features of Python / Say something about the benefits of using Python?
Python is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning Python:
○ Simple and easy to learn:
* Learning python programming language is easy and fun.
* Compared to other language, like, Java or C++, its syntax is a way lot easier.
* You also don’t have to worry about the missing semicolons (;) in the end!
* It is more expressive means that it is more understandable and readable.
* Python is a great language for the beginner-level programmers.
* It supports the development of a wide range of applications from simple text processing to WWW browsers to games.
* Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax. This makes it easy for Beginners to pick up the language quickly.
* Easy-to-read − Python code is more clearly defined and readable. It's almost like plain and simple English.
* Easy-to-maintain − Python's source code is fairly easy-to-maintain.
Features of Python
○ Python is Interpreted −
* Python is processed at runtime by the interpreter.
* You do not need to compile your program before executing it. This is similar to PERL and PHP.
○ Python is Interactive −
* Python has support for an interactive mode which allows interactive testing and debugging of snippets of code.
* You can open the interactive terminal also referred to as Python prompt and interact with the interpreter directly to write your programs.
○ Python is Object-Oriented −
* Python not only supports functional and structured programming methods, but Object Oriented Principles.
○ Scripting Language —
* Python can be used as a scripting language or it can be compliled to byte-code for building large applications.
○ Dynammic language —
* It provides very high-level dynamic data types and supports dynamic type checking.
○ Garbage collection —
* Garbage collection is a process where the objects that are no longer reachable are freed from memory.
* Memory management is very important while writing programs and python supports automatic garbage collection, which is one of the main problems in writing programs using C & C++.
○ Large Open Source Community —
* Python has a large open source community and which is one of its main strength.
* And its libraries, from open source 118 thousand plus and counting.
* If you are stuck with an issue, you don’t have to worry at all because python has a huge community for help. So, if you have any queries, you can directly seek help from millions of python community members.
* A broad standard library − Python's bulk of the library is very portable and cross-platform compatible on UNIX, Windows, and Macintosh.
* Extendable − You can add low-level modules to the Python interpreter. These modules enable programmers to add to or customize their tools to be more efficient.
○ Cross-platform Language —
* Python is a Cross-platform language or Portable language.
* Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
* Python can run on different platforms such as Windows, Linux, Unix and Macintosh etc.
Explain the features of Python / Say something about the benefits of using Python?
Python is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Web Development Domain. I will list down some of the key advantages of learning Python:
○ Simple and easy to learn:
* Learning python programming language is easy and fun.
* Compared to other language, like, Java or C++, its syntax is a way lot easier.
* You also don’t have to worry about the missing semicolons (;) in the end!
* It is more expressive means that it is more understandable and readable.
* Python is a great language for the beginner-level programmers.
* It supports the development of a wide range of applications from simple text processing to WWW browsers to games.
* Easy-to-learn − Python has few keywords, simple structure, and a clearly defined syntax. This makes it easy for Beginners to pick up the language quickly.
* Easy-to-read − Python code is more clearly defined and readable. It's almost like plain and simple English.
* Easy-to-maintain − Python's source code is fairly easy-to-maintain.
Features of Python
○ Python is Interpreted −
* Python is processed at runtime by the interpreter.
* You do not need to compile your program before executing it. This is similar to PERL and PHP.
○ Python is Interactive −
* Python has support for an interactive mode which allows interactive testing and debugging of snippets of code.
* You can open the interactive terminal also referred to as Python prompt and interact with the interpreter directly to write your programs.
○ Python is Object-Oriented −
* Python not only supports functional and structured programming methods, but Object Oriented Principles.
○ Scripting Language —
* Python can be used as a scripting language or it can be compliled to byte-code for building large applications.
○ Dynammic language —
* It provides very high-level dynamic data types and supports dynamic type checking.
○ Garbage collection —
* Garbage collection is a process where the objects that are no longer reachable are freed from memory.
* Memory management is very important while writing programs and python supports automatic garbage collection, which is one of the main problems in writing programs using C & C++.
○ Large Open Source Community —
* Python has a large open source community and which is one of its main strength.
* And its libraries, from open source 118 thousand plus and counting.
* If you are stuck with an issue, you don’t have to worry at all because python has a huge community for help. So, if you have any queries, you can directly seek help from millions of python community members.
* A broad standard library − Python's bulk of the library is very portable and cross-platform compatible on UNIX, Windows, and Macintosh.
* Extendable − You can add low-level modules to the Python interpreter. These modules enable programmers to add to or customize their tools to be more efficient.
○ Cross-platform Language —
* Python is a Cross-platform language or Portable language.
* Python can run on a wide variety of hardware platforms and has the same interface on all platforms.
* Python can run on different platforms such as Windows, Linux, Unix and Macintosh etc.
#interviewQuestions : 0003
What is Python good for?
Python is a high-level general-purpose programming language that can be applied to many different classes of problems.
The language comes with a large standard library that covers areas such as string processing (regular expressions, Unicode, calculating differences between files), Internet protocols (HTTP, FTP, SMTP, XML-RPC, POP, IMAP, CGI programming), software engineering (unit testing, logging, profiling, parsing Python code), and operating system interfaces (system calls, filesystems, TCP/IP sockets). Look at the table of contents for The Python Standard Library to get an idea of what’s available. A wide variety of third-party extensions are also available.
What is Python good for?
Python is a high-level general-purpose programming language that can be applied to many different classes of problems.
The language comes with a large standard library that covers areas such as string processing (regular expressions, Unicode, calculating differences between files), Internet protocols (HTTP, FTP, SMTP, XML-RPC, POP, IMAP, CGI programming), software engineering (unit testing, logging, profiling, parsing Python code), and operating system interfaces (system calls, filesystems, TCP/IP sockets). Look at the table of contents for The Python Standard Library to get an idea of what’s available. A wide variety of third-party extensions are also available.
Which of the following statement(s) is TRUE?
Anonymous Quiz
24%
A hash function takes a message of arbitrary length and generates a fixed length code.
24%
A hash function takes a message of fixed length and generates a code of variable length.
38%
All above
14%
None of the above
What is the output of the following program :
print('{0:.2}'.format(1.0 / 3))
print('{0:.2}'.format(1.0 / 3))
Anonymous Quiz
21%
0.333333
36%
0.33
11%
0.333333:-2
32%
Syntax error
What is the output of this statement
print ((1,2,3) <(1,2,4))
print ((1,2,3) <(1,2,4))
Anonymous Quiz
53%
True
25%
False
4%
None
14%
Error
4%
None of the above
Unlike Python 2,
Python 3 fully supports Unicode.
Python 3 fully supports Unicode.
Anonymous Quiz
48%
Correct
23%
In-correct, both versions fully support unicode.
16%
In-correct, both versions support unicode with some limitation.
13%
Show me the answer
#interviewQuestions : 0004
Is Python a Scripting Language?
Python is capable of scripting, but it is more than that. It is considered as a general-purpose programming language.
Is Python a Scripting Language?
Python is capable of scripting, but it is more than that. It is considered as a general-purpose programming language.
#interviewQuestions : 0005
Is Python interpreted or compiled?
A common question: “Is Python interpreted or compiled?” Usually, the asker has a simple model of the world in mind, and as is typical, the world is more complicated.
In the simple model of the world, “compile” means to convert a program in a high-level language into a binary executable full of machine code (CPU instructions). When you compile a C program, this is what happens. The result is a file that your operating system can run for you.
In the simple definition of “interpreted”, executing a program means reading the source code a line at a time, and doing what it says.
Compiling is a more general idea: take a program in one language (or form), and convert it into another language or form.
In Python, the source code is compiled into a much simpler form called bytecode. These are instructions similar in spirit to CPU instructions, but instead of being executed by the CPU, they are executed by software called a virtual machine.
So, if you can explain all this, then you can say its both a compiled and interpreted language.
But, if you want to give a simple and short answer, then say it is a interpreted language.
Is Python interpreted or compiled?
A common question: “Is Python interpreted or compiled?” Usually, the asker has a simple model of the world in mind, and as is typical, the world is more complicated.
In the simple model of the world, “compile” means to convert a program in a high-level language into a binary executable full of machine code (CPU instructions). When you compile a C program, this is what happens. The result is a file that your operating system can run for you.
In the simple definition of “interpreted”, executing a program means reading the source code a line at a time, and doing what it says.
Compiling is a more general idea: take a program in one language (or form), and convert it into another language or form.
In Python, the source code is compiled into a much simpler form called bytecode. These are instructions similar in spirit to CPU instructions, but instead of being executed by the CPU, they are executed by software called a virtual machine.
So, if you can explain all this, then you can say its both a compiled and interpreted language.
But, if you want to give a simple and short answer, then say it is a interpreted language.
Which is faster in performance while searching around a million records plus?
Anonymous Quiz
23%
List
10%
Set
24%
Dict
20%
Tuple
13%
All have the same performance
9%
See the answer
#interviewQuestions : 0006
What is pep 8?
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
PEP stands for Python Enhancement Proposal, and there are several of them. A PEP is a document that describes new features proposed for Python and documents aspects of Python, like design and style, for the community.
What is pep 8?
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
PEP stands for Python Enhancement Proposal, and there are several of them. A PEP is a document that describes new features proposed for Python and documents aspects of Python, like design and style, for the community.