Python Programming Quiz

Quiz on Basic Concepts in Python

Time left: 300 seconds

Q.1. What is the correct file extension for Python files?

Select Your Option

Every python file will give the .py extension when saved.

Q.2. What is the output of the following code?
          
            listOne = [20, 40, 60, 80]
            listTwo = [20, 40, 60, 80]
            
            print(listOne == listTwo)
            print(listOne is listTwo)
          
          

Select Your Option

The '==' operator in Python compares the value of the 2 operands while the 'is' operator in Python checks whether both the operands point to the same object in memory. In the question, listOne and listTwo may have the same values (hence, we get True when we use == operator) but they are 2 different objects pointing to different memory locations.

Q.3. What is the output of the following code?
          
            var= "James Bond"
            print(var[2::-1])
          
          

Select Your Option

The string is sliced starting from index 2 and going in reverse direction with step 1.

Q.4. Which of the following is correct?

Select Your Option

Comments are guidelines included by the programmer to increase the readablity of the code for the user. All of the statements in the question are true for comments in Python.

Q.5. Python syntax is case-sensitive.

Select Your Option

Python is case-sensitive as it treats uppercase and lowercase characters differently..

Q.6. Which operator has higher precedence in the following list

Select Your Option

For order of precedence, remember PEMDAS-Parentheses> Exponential> Multiplication> Division> Addition> Subtraction.

Q.7. What is the output for -
          
            'python ' [-3]
          
          

Select Your Option

-3 implies the 3rd index starting from the right end of the string. In given string, the character 'h' is found at the said index.

Q.8. What is output of following code -
          
            x = 2
            y = 10
            x * = y * x + 1
          
          

Select Your Option

The given expression is evaluated as: x = x * (y*x+1) = 2 * (10*2+1). After evaluating the expression according to the order of precedence of the operators, we get the value of x as 42.

Q.9. What is the output of the following code?
          
            str = "pynative"
            print (str[1:3])
          
          

Select Your Option

The given string is sliced from index 1 to 3 but the last index is not inclusive. Hence, the characters at indices 1 and 2 will be printed.

Q.10. The 'in' operator is used to check if a value exists within an iterable object container such as a list. This operation returns True if it finds the specified value in the specified sequence and False otherwise.

Select Your Option

The given statement is True for 'in' operator in Python.

Q.11. What is output for:
          
            max(''please help '')
          
          

Select Your Option

With a single iterable argument, the max function returns its biggest item. Within the provided string, 's' has the biggest ASCII value.

Q.12. What is the output of the following code?
          
            def nprint(message, n):
                while(n > 0):
                   print(message)
                n-=1
            nprint('z', 5)
          
          

Select Your Option

The value of n is updated outside the loop. Hence, for infinity inside the loop, the value of n will always be 5 (which is > 0). Hence the system will enter an infinite loop.

Q.13. What is the possible output of the following code?
          
            sampleSet = {"Jodi", "Eric", "Garry"}
            sampleSet.add("Vicki")
            print(sampleSet)
          
          

Select Your Option

A set is an unordered item. There will be many possible outcomes including option A and option B.

Q.14. What is the output of the following code?
          
            var = "James" * 2  * 3
            print(var)
          
          

Select Your Option

Evaluating the string from left to right, we see "James" is repeated 6 times.

Q.15. What is the output of the following code?
          
            p, q, r = 10, 20 ,30
            print(r, p, q)
          
          

Select Your Option

The first statement simlutaneously assigns the values 10, 20 and 30 to p, q and r respectively.

Instructions:-

  1. This Quiz is based on the basic concepts of Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post