Python Questions
5.35K 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 of the following operators has the lowest precedence?
Anonymous Quiz
28%
not
12%
and
13%
**
28%
+
18%
%
y, z = 10, 15
y *= y + z
# What is the value of y. Explain How?
Anonymous Quiz
5%
10
5%
15
15%
25
21%
115
44%
250
5%
None of the above
6%
Show me the answer
min("abCD123!")

# What is the output and WHY?
Anonymous Quiz
12%
a
5%
C
16%
1
15%
!
26%
abCD123!
16%
None of the above
11%
Show me the answer
#interviewQuestions : 0011

Q: Explain the following assignment?

x, y, z = 5, 10, 15
a = b = c = 0

a = x - z
x -= z

b = y - y + z
y -= (y + z)
print(b, y)

15 -15

Notice
the result in the here, it should be 15 and 15, but the value of y is -15.
Do you know why?
When the statements are evaluated, the statements are evaluated from left to right. But before that, anything within the braces are executed first.

So, in the first statement, since there is no curly braces, it first executes y - y and the result + z, this becomes 15
In the second statement, the expression within curly braces is executed, which is y + z, which comes to 25 and then now the expression becomes y -= 25, which is same as y = y- 25, hence the result -15.
#interviewQuestions : 0012

What is PYTHONPATH?

PYTHONPATH is an environment variable can be set, to add additional directories where python will look for modules and packages.

Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.

For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.

The only reason to set PYTHONPATH is to maintain directories of custom Python libraries that you do not want to install in the global default location (i.e., the site-packages directory).
#interviewQuestions : 0013

What are python modules?

Python modules are files containing Python code.

A module can define functions, classes and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use.
x = [3,1,2]
What is the output of x [1:-1]? Explain Why?
Anonymous Quiz
13%
3,1,2
13%
3,1
30%
1,2
28%
1
10%
None of the above
6%
Show me the answer
Which of the following programming styles does Python support?
Anonymous Quiz
7%
Functional
9%
Procedural
30%
Object Oriented
50%
All of the above
4%
Show me the answer
print('abcefd'.replace('cd', '12'))

#What is the output of the above code?
Anonymous Quiz
28%
ab1ef2
14%
ab12ef12
4%
ab1efd
3%
abcef2
22%
abcefd
21%
None of the above
7%
Show me the answer
x = 5,000.00

#What is the value of x. Explain Why?
Anonymous Quiz
8%
5
2%
(5)
8%
(5,0.0)
22%
5000
7%
(5000)
29%
5000.00
14%
(5,000.00)
9%
Show me the answer
Which of these in not a core datatype in Python 3?
Anonymous Quiz
4%
Lists
8%
Dictionary
43%
Class
5%
Tuple
35%
All are core data types
6%
Show me the answer
x = (round(4.5) - - round(-4.5))

# What is the value of x? Explain Why?
Anonymous Quiz
34%
0
13%
9
8%
-9
18%
8
4%
-8
14%
Syntax Error
8%
Show me the answer
x = 5,000,000.00
type(x)
# What is the datatype of x? Explain Why?
Anonymous Quiz
6%
str
21%
int
53%
float
3%
list
8%
tuple
6%
Syntax Error
3%
Show me the answer
What is the maximum length allowed for an identifier in Python 3?
Anonymous Quiz
17%
64
13%
128
20%
256
21%
1024
18%
None of the above
11%
Show me the answer
'{} was created by {1} and first released in {2}'.format('Python','Guido van Rossum','1991')

#What is the output of the code shown above?
Anonymous Quiz
62%
Python was created by Guido van Rossum and first released in 1991
15%
Guido van Rossum was created by 1991 and first released in Python
9%
{} was created by {1} and first released in {2}
9%
Error
6%
Show me the answer
x = - - -5

#What is the value of x
Anonymous Quiz
13%
5
54%
-5
4%
11
4%
-11
15%
None of the above
10%
Show me the answer
Which of the following is a valid statement and runs without error?
Anonymous Quiz
53%
round(45.8)
8%
round(7463.123.3.3)
20%
round()
8%
round(6352.898,2,5)
6%
None of the above
6%
Show me the answer
x = bin((3**9) -1) == '{}'.format(bin((3**9) -1))

What is the value of x? Explain?
Anonymous Quiz
20%
19682
30%
True
19%
False
11%
729
7%
None of the above
13%
Show me the answer
x='{0}, {1}, and {2}'
x.format('hello', 'Python Club', 'members')
# What is the output of this code.
Anonymous Quiz
29%
‘hello Python Club and members’
22%
‘hello, Python Club, members’
28%
‘hello, Python Club, and members’
17%
Syntax Error
4%
Show me the answer