This Python Operators and Expression quiz provide Multiple Choice Questions (MCQ) to get familiar with all operators of Python.
Also, See: Python Operators.
- The quiz contains 15 Questions. Solve 10 correct to pass the test.
- You will have to read all the given answers and click over the correct answer.
- The page will reload after Quiz submission. After submission, scroll the page to view the result.
hi can you please explain question no 13..?? i.e output of the addition operator
x = 6
y = 2
print(x ** y)# ** reprise the power of like 6^2 = 36
print(x // y)# this is tricky one
# so '//' this operator divide the and round down to zero
# if it was
x = 7
y = 2
print(x // y) # the result will be 3.5 in normal division '/' here it takes the extra after the dot '.' out
a = [10, 20]
b = a
b += [30, 40]
print(a)
print(b)
# we can modify the list we can’t modify strings the above is the list so it’s when modified it reflects on both
here, we need to consider as 3 power 2(3**2) = 9
then, 2 power 9(2**9(3**2)) = 512
in question 13 there is no addition operator. may be you mention the wrong question no.
14%5
25%8
explain this bro
In Python, When we join two non-Boolean values using a and operator, the value of the expression is the second operands, not True or False.
this is and operator so and operator compare both value if first value match to variable and then go for second value and print second variable value as a result for non boolen value.
Wow this quiz helped me a lot
Also the comment section is so educative I appreciate.
print(-18//4)
The answer is -5
But I don’t know how is it come as -5
Could you tell me how actually it works?
By using floor division we always round off to smaller value if you divide 18÷4 you get 4.5 but as 18 is negative so we round it off to smaller value -4.5 to -5 .
Thank you.
Really great quiz Bhai . The content is very informative. GOD BLESS YOU.
I am beginner to python how can we solve this?
please apply (BODMAS) method
nice gud
PEMDAS
answer is = 4.0
What is the answer?
6<<2
x = 5 + 4 * 9 % (3 + 1) / 6 - 1
print(x)
Inside the parentheses, (3 + 1) evaluates to 4.
The modulo operator % calculates the remainder of 9 divided by 4, which is 1.
Multiplication: 4 * 9 equals 36.
Division: 1 / 6 equals 0.16666666666666666.
Addition: 5 + 36 equals 41.
Subtraction: 41 – 1 equals 40.
Therefore, the result of the expression
5 + 4 * 9 % (3 + 1) / 6 - 1
is 40.4.0
usig priorities
What will be the output of
1 is correct
NameError
What is the output of the following?
print( (2+3) * 4 );
Amazing quiz!!!
I get to understand operator precedence clearly, Thanks 🙂
You are welcome, fareen.
Which extension is used to save Python program file.?.
Please use
.py
Hi, in Q8, explanation is:
In Python, When we join two non-Boolean values using a and operator, the value of the expression is one of the operands, not True or False.
but should be:
In Python, When we join two non-Boolean values using a and operator, the value of the expression is the second of the operands, not True or False.
With operator OR is the first: am I wrong?
Thank you, Giorgio, for the suggestion. I have updated the explanation
I want an explanation of example 8, suppose instead of the list if I will give string why the value of a is not concatenating with b?
Please reply to this
Output:
‘Hi’
Hi Himanshu, Those are different variables pointing to the different memory addresses. For Example:
Output:
Is it only applicable to a list? Why is it not applicable to a tuple or string?
Because you have stored a string in the variable – c
The
+=
operator does not work in the similar fashion as it does for list, tuples and numeric values.Change the values to a tuple or a list or a number and you will see the difference.
str data type is immutable. Therefor once you created an str object you can’t modify its content. If you are trying to change its content, then with those changes a new object will be created.
Here c and d pointing to the same object. You are trying to change its content using the reference d. Therefor a new object will be created and d now pointing to the newly created object. But c pointing to the old object only.
If you try to print d then you will get ‘HiHimanshu’.
Also you can try using “is” operator. is operator returns true if and only if two references share the same object.
print(c is d) will give you False. Because c and d now pointing to different objects.
What will be the output of following expression
i]7/2 ii]7//2
i] 3.5
ii] 3
What is the output of print (
7%21
)7
c="hi"
d=c
d+="hoddy"
print(c)
print(d)
output:
hi
hihoddy