Python Programming Quiz

Quiz on String Manipulation in Python

Time left: 300 seconds

Q.1. Select the correct output of the following String operations
          
            strOne = str("HFC")
            strTwo = "HFC"
            print(strOne == strTwo)
            print(strOne is strTwo)
          
          

Select Your Option

The '==' operator compares the value or equality of two objects, whereas the Python 'is' operator checks whether two variables point to the same object in memory.

Q.2. Select the correct output of the following String operations
          
            x = 'abcd'
            for i in x:
                print(i.upper())
          
          

Select Your Option

he upper() method returns a string where all characters are in upper case. Inside the for loop, the instance of the string returned by upper() is being printed.

Q.3. What is a string?

Select Your Option

Strings in Python are arrays of bytes representing unicode characters.

Q.4. Select the correct output of the following String operations
          
            s = 'foo'
            t = 'bar'
            print('barf' in 2 * (s + t))
          
          

Select Your Option

s+t = foobar; 2*(s+t) = foobarfoobar; hence, we have the string 'barf' in 2*(s+t).

Q.5. Which method should I use to convert String "welcome to the beautiful world of python" to "Welcome
To The Beautiful World Of Python"

Select Your Option

The title() function capitalizes the first letter of every word of the String.

Q.6. What will be the output of the following Python statement?
          
            print("a"+"bc")
          
          

Select Your Option

Here, the '+' operator is concatenation operator.

Q.7. What is the output of the following string operations?
          
            str = "My salary is 7000";
            print(str.isalnum())
          
          

Select Your Option

Space is not an alpha numberic character. isalnum() checks the whole string if all characters are alphanumeric or not.

Q.8. What is the result of this statement?
          
            print(ord('foo'))
          
          

Select Your Option

The ord() function returns the integer value for a given character. But you can only specify a single character (a string of length 1)

Q.9. For strings, the symbol '+' means

Select Your Option

The '+' operator is concatenation operator.

Q.10. Method issubclass() checks if a class is a subclass of another class.

Select Your Option

+ is used to concatenate and * is used to multiply strings.

Q.11. What will be the output of the following Python code?
          
            print("abc. DEF".capitalize())
          
          

Select Your Option

The capitalize() function converts the first letter of the string to uppercase and the other charactes to lowercase.

Q.12. What will be the output of the following Python code?
          
            str1 = 'Welcome'
            print (str1[:6] + ' HFC')
          
          

Select Your Option

The + operator is used for concatenating. To get a substring from the original string, we can use a slice [], operator. The string "Welcome" is sliced from index 0 to 5 by use of str1[:6]

Q.13.Which function is called when the following Python program is executed?
          
            f = foo()
            format(f)
          
          

Select Your Option

Both str(f) and format(f) call f.__str__().

Q.14. What is the output of the following code?
          
            x="BOnvoyage"
            print(x[3: ])
          
          

Select Your Option

Index start from 0 so at 3 'v' exist so the output will be from v to last letter of string.

Q.15. What is the output of the following code?
          
            print('*', "abcde".center(6), '*', sep='')
          
          

Select Your Option

Padding is done towards the right-hand-side first when the final string is of even length.

Instructions:-

  1. This Quiz is based on String Manipulation in 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