Strings in Python

Description

Coding Python Quiz on Strings in Python, created by PathaPadha Support on 27/10/2020.
PathaPadha Support
Quiz by PathaPadha Support, updated more than 1 year ago
PathaPadha Support
Created by PathaPadha Support over 3 years ago
1440
0

Resource summary

Question 1

Question
Select the correct output of the following String operations strOne = str("pynative") strTwo = "pynative" print(strOne == strTwo) print(strOne is strTwo)
Answer
  • false false
  • true true
  • true false
  • false true

Question 2

Question
Python does not support a character type; a single character is treated as strings of length one.
Answer
  • True
  • False

Question 3

Question
Choose the correct function to get the ASCII code of a character
Answer
  • char(‘char’)
  • ord(‘char’)
  • ascii(‘char’)

Question 4

Question
Select the correct output of the following String operations str1 = 'Welcome' print (str1[:6] + ' PYnative')
Answer
  • Welcome PYnative
  • WelcomPYnative
  • Welcom PYnative
  • WelcomePYnative

Question 5

Question
What is the output of the following string operations ? str = "My salary is 7000"; print(str.isalnum())
Answer
  • True
  • False

Question 6

Question
Choose the correct function to get the character from ASCII number
Answer
  • ascii(‘number)
  • char(number)
  • chr(number)

Question 7

Question
What is the output of the following string comparison ? print("John" > "Jhon") print("Emma" < "Emm")
Answer
  • True False
  • False False

Question 8

Question
Select the correct output of the following String operations myString = "pynative" stringList = ["abc", "pynative", "xyz"] print(stringList[1] == myString) print(stringList[1] is myString)
Answer
  • true false
  • true true

Question 9

Question
Guess the correct output of the following code ? str1 = "PYnative" print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
Answer
  • PYn PYnat ive PYnativ vitanYP
  • Yna PYnat tive PYnativ vitanYP
  • Yna PYnat tive PYnativ PYnativ

Question 10

Question
Strings are immutable in Python, which means a string cannot be modified.
Answer
  • True
  • False

Question 11

Question
Guess the correct output of the following String operations str1 = 'Welcome ' print(str1*2)
Answer
  • WelcomeWelcome
  • TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
  • Welcome Welcome
  • Welcome2

Question 12

Question
Select the correct output of the following String operations str = "my name is James bond"; print (str.capitalize())
Answer
  • My Name Is James Bond
  • TypeError: unsupported operand type(s) for * or pow(): ‘str’ and ‘int’
  • My name is james bond

Question 13

Question
Which method should I use to convert String "welcome to the beautiful world of python" to "Welcome To The Beautiful World Of Python" ?
Answer
  • capitalize()
  • title()

Question 14

Question
Select the correct output of the following String operations str1 = "my isname isisis jameis isis bond"; sub = "is"; print(str1.count(sub, 4))
Answer
  • 5
  • 6
  • 7
  • 4

Question 15

Question
What is the output of the following code ? str1 = "My salary is 7000"; str2 = "7000" print(str1.isdigit()) print(str2.isdigit())
Answer
  • False True
  • False False
  • True False
Show full summary Hide full summary

Similar

Python Quiz
karljmurphy
Think Python
tsilvo2001
Basic Python - Print Formatting
Rebecca Noel
What is Python?
Daniel Ingram
Python
54671
Know your Python!
educ8ict
Basic Python - Strings
Rebecca Noel
Study on IoT systems design
Tomasz Cieplak
Python
Kirstie Wu
OpenSource Programming
Faheem Ahmed
Basic Python - Lists
Rebecca Noel