PYnative

Python Programming

  • Learn Python
  • Exercises
  • Quizzes
  • Code Editor
  • Tricks
Home » Python » Quizzes » Python Operators and Expression Quiz

Python Operators and Expression Quiz

Updated on: August 24, 2022 | 45 Comments

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.

1. What is the output of print(10 - 4 * 2)

 
 

2. What is the output of print(2 ** 3 ** 2)

 
 

3. What is the value of the following Python Expression

print(36 / 4)

 
 

4. What is the output of print(2 * 3 ** 3 * 4)

 
 

5. 4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?

a = 4
b = 11
print(a | b)
print(a >> 2)
 
 

6. What is the output of print(2%6)

 
 
 

7. What is the output of the following code

x = 100
y = 50
print(x and y)
 
 
 
 

8. What is the output of the following assignment operator

y = 10
x = y += 2
print(x)
 
 
 

9. Bitwise shift operators (<<, >>) has higher precedence than Bitwise And(&) operator

 
 

10. What is the output of the following code

x = 6
y = 2
print(x ** y)
print(x // y)
 
 
 
 

11. What is the output of the following code

print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))

 
 
 
 

12. What is the output of the following Python code

x = 10
y = 50
if x ** 2 > 100 and y < 100:
    print(x, y)
 
 
 

13. What is the output of the following addition (+) operator

a = [10, 20]
b = a
b += [30, 40]
print(a)
print(b)
 
 

14. What is the output of the expression  print(-18 // 4)

 
 
 
 

15. Which of the following operators has the highest precedence?

Hint: Python operators precedence

 
 
 
 

Loading ... Loading …

Loading

Filed Under: Python, Python Basics, Python Quizzes

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, Founder of PYnative.com. I am a Python developer, and I love to write articles to help students, developers, and learners. Follow me on Twitter

Related Tutorial Topics:

Python Python Basics Python Quizzes

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 10 questions
  • Each Quiz contains 12-15 MCQ
Exercises
Quizzes

Comments

  1. Shweta Arya says

    December 1, 2022 at 2:09 pm

    hi can you please explain question no 13..?? i.e output of the addition operator

    Reply
    • bandar says

      December 21, 2022 at 9:32 am

      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

      Reply
    • bandar@inmecca.com says

      December 21, 2022 at 9:40 am

      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

      Reply
    • saisuryateja reddy says

      February 17, 2023 at 10:53 am

      here, we need to consider as 3 power 2(3**2) = 9
      then, 2 power 9(2**9(3**2)) = 512

      Reply
    • riya says

      July 16, 2023 at 8:47 pm

      in question 13 there is no addition operator. may be you mention the wrong question no.

      Reply
  2. Khutso Shaun says

    October 13, 2022 at 8:11 pm

    14%5
    25%8

    Reply
  3. venky says

    October 12, 2022 at 3:33 am

    x = 100
    y = 50
    print(x and y)

    explain this bro

    Reply
    • Tanveer says

      November 22, 2022 at 9:20 pm

      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.

      Reply
    • sunul says

      July 10, 2023 at 11:06 pm

      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.

      Reply
  4. khethiwe says

    May 17, 2022 at 2:01 pm

    Wow this quiz helped me a lot

    Reply
  5. Zuenah Macharia says

    March 16, 2022 at 11:24 am

    Also the comment section is so educative I appreciate.

    Reply
  6. Rakhesh says

    November 11, 2021 at 8:01 pm

    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?

    Reply
    • Vaishnavi says

      January 31, 2022 at 11:58 pm

      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.

      Reply
  7. kinnu says

    November 9, 2021 at 9:02 pm

    Really great quiz Bhai . The content is very informative. GOD BLESS YOU.

    Reply
  8. shivani says

    June 27, 2021 at 4:14 pm

    I am beginner to python how can we solve this?

    5 + 4 * 9 % (3 + 1) / 6 - 1
    Reply
    • Priya says

      August 2, 2021 at 4:43 pm

      please apply (BODMAS) method

      Reply
      • panimalar says

        October 18, 2022 at 2:20 pm

        nice gud

        Reply
      • Varun TK says

        January 25, 2023 at 6:51 pm

        PEMDAS

        Reply
    • prakas shrestha says

      November 16, 2021 at 7:07 am

      5+36%4/6-1
      5+0/6-1
      5+0-1

      answer is = 4.0

      Reply
    • Kuldeep Kaur says

      February 16, 2022 at 11:36 am

      What is the answer?

      6<<2

      Reply
    • Abdul-Malik says

      June 14, 2023 at 4:30 pm

      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

      Reply
    • vamsi says

      September 14, 2023 at 10:51 am

      usig priorities

      Reply
  9. Loveleen says

    March 15, 2021 at 6:41 pm

    What will be the output of

    x=73
    y=x%9
    Print (y)
    Reply
    • parshu nepal says

      June 2, 2021 at 10:20 pm

      here  73 % 9
       is 9)73(8
             - 72
            - - - - - - -
                1 is remainder.
       so, it prints 1.
      Reply
    • Gurumoorthy says

      August 31, 2022 at 8:28 am

      1 is correct

      Reply
    • Abdul-Malik says

      June 14, 2023 at 4:27 pm

      NameError

      Reply
  10. HEMISH says

    February 23, 2021 at 4:46 am

    What is the output of the following? print( (2+3) * 4 );

    Reply
    • parshu nepal says

      June 2, 2021 at 10:24 pm

      according to REPL
       ((2+3)*4) first solves () 
       so, 2+3=5
       and 5*4. which result 20.
      Reply
  11. fareen says

    November 5, 2020 at 9:59 am

    Amazing quiz!!!
    I get to understand operator precedence clearly, Thanks 🙂

    Reply
    • Vishal says

      November 6, 2020 at 5:09 pm

      You are welcome, fareen.

      Reply
  12. Priyam says

    October 2, 2020 at 12:24 pm

    Which extension is used to save Python program file.?.

    Reply
    • Vishal says

      October 5, 2020 at 9:35 am

      Please use .py

      Reply
  13. Giorgio Incantawolf says

    June 19, 2020 at 10:51 pm

    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?

    Reply
    • Vishal says

      June 20, 2020 at 7:24 pm

      Thank you, Giorgio, for the suggestion. I have updated the explanation

      Reply
  14. Himanshu says

    March 17, 2020 at 5:17 pm

    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

    c="Hi"
    d=c
    d+="Himanshu"
    print(c)

    Output:
    ‘Hi’

    Reply
    • Vishal says

      March 18, 2020 at 3:48 pm

      Hi Himanshu, Those are different variables pointing to the different memory addresses. For Example:

      c="Hi"
      d=c
      d+="Himanshu"
      
      print(id(c))
      print(id(d))

      Output:

      Hi
      139957838277800
      139957815075824
      Reply
      • G says

        February 11, 2022 at 10:31 pm

        Is it only applicable to a list? Why is it not applicable to a tuple or string?

        Reply
    • Trisha says

      March 25, 2020 at 8:02 pm

      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.

      Reply
    • Sreerag says

      June 22, 2020 at 10:26 pm

      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.

      Reply
      • Sreerag says

        June 22, 2020 at 10:30 pm

        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.

        Reply
    • Pavani says

      November 4, 2020 at 9:15 am

      What will be the output of following expression
      i]7/2 ii]7//2

      Reply
      • amit says

        June 13, 2021 at 1:23 am

        i] 3.5
        ii] 3

        Reply
    • ABHISHEK says

      September 7, 2021 at 2:06 pm

      What is the output of print (7%21)

      Reply
      • prakas shrestha says

        November 16, 2021 at 7:25 am

        7

        Reply
    • Aamir says

      February 16, 2023 at 5:23 pm

      c="hi"
      d=c
      d+="hoddy"
      print(c)
      print(d)

      output:
      hi
      hihoddy

      Reply

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

Posted In

Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

  • Python Quizzes Home
  • Basic Quiz For Beginners
  • Variables and Data Types Quiz
  • Operators and Expression Quiz
  • Input and Output Quiz
  • Functions Quiz
  • if else and loops Quiz
  • Numbers Quiz
  • String Quiz
  • List Quiz
  • Set Quiz
  • Dictionary Quiz
  • Tuple Quiz
  • File Handling Quiz
  • Random Data Generation Quiz

All Python Topics

Python Basics Python Exercises Python Quizzes Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our Terms Of Use, Cookie Policy, and Privacy Policy.

Copyright © 2018–2023 pynative.com