Python Questions
5.34K subscribers
1 photo
7 links
Tasks for Beginners, Interview Questions, Regular expressions, simple coding problems, Quiz etc.

Useful Resources — »»» @python_resources_iGnani
Projects for Practice — »»» @python_projects_repository
Discussion Forum — »»» @python_programmers_club
Download Telegram
Which operator is right-associative among these?
Anonymous Quiz
26%
+
16%
*
43%
=
15%
%
In Python, functions can also have attributes and methods.
Anonymous Quiz
11%
Only Attributes
7%
Only Methods
79%
Both Attribures & Methods
3%
None
How can we check whether the object is instance of class or not.
For example, how to check if an object O which is instance of class C.
Anonymous Quiz
29%
C.isinstance(O)
40%
O.isinstance(C)
25%
isinstance(O,C)
7%
isinstance(C,O)
Python Questions
What is output of following code?
x = (5, 7)
x[0] +=3
Answer
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?
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?
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:
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.
#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.
#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 the output of the following program :
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))
Anonymous Quiz
53%
True
25%
False
4%
None
14%
Error
4%
None of the above
#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.