0% found this document useful (0 votes)
4 views4 pages

Python String Methods

The document provides an overview of various string methods in Python, including capitalization, case conversion, counting characters, and checking string beginnings and endings. It also includes multiple-choice questions (MCQs) related to string operations and their expected outputs. The examples demonstrate how to manipulate strings and test understanding of string properties.

Uploaded by

nielitlkoccc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python String Methods

The document provides an overview of various string methods in Python, including capitalization, case conversion, counting characters, and checking string beginnings and endings. It also includes multiple-choice questions (MCQs) related to string operations and their expected outputs. The examples demonstrate how to manipulate strings and test understanding of string properties.

Uploaded by

nielitlkoccc
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

#string methods

s="hello this is python"


st="Hello"
sst="Avatar the Way of Water"
#How to capitalize first character of a
string---capitalize()
print([Link]())
#how to convert my string to lowercase
print([Link]())
print([Link]())
#how to center a string in python with
specified characters
#center(length,string char)
print([Link](15,"X"))
#how to count the no. of time a character is
present in a string?
print([Link]("l"))
print([Link]("t"))
#How to check wheather a string start with a
specific character?
print([Link]("Avatar"))
#---True/False---boolean values
#how to check wheather a string ends with a
specific character?
print([Link]("Water"))

s="hello\tthis\tis\tpython"
#how to modify the spaces between the string
given by \t escape sequence
#by default the tab==8 spaces in python
print(s)
print([Link](8))
print([Link](10))
s="hello this is python"
#how to get the starting index of a
substring present in a string?
#use find() function---returns index of
first occurence of the string character
print([Link]("this"))#----6
print([Link]("i"))#---8
#How to find the last occurence of a
character in a string?--rfind()
print([Link]("i"))#---11

MCQS
1)What will be the output of above Python code?

str1="6/4"

print("str1")

2)Which of the following will result in an error?

str1="python"

A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)

3)Which of the following is False?

A. String is immutable.
B. capitalize() function in string is used to return a string by converting the
whole given string into uppercase.
C. lower() function in string is used to return a string by converting the
whole given string into lowercase.
D. None of these.
4)What will be the output of below Python code?

str1="Information"

print(str1[2:8])

A. format
B. formatio
C. orma
D. ormat

5)What will be the output of below Python code?

str1="Aplication"

str2=[Link]('a','A')

print(str2)

A. application
B. Application
C. ApplicAtion
D. applicAtion

6)What will be the output of below Python code?

str1="poWer"

[Link]()

print(str1)

A. POWER
B. Power
C. power
D. poWer
7) What will the below Python code will return?
str1="save paper,save plants"

print([Link]("save"))

A. It returns the first index position of the first occurance of "save" in the
given string str1.
B. It returns the last index position of the last occurance of "save" in the
given string str1.
C. It returns the last index position of the first occurance of "save" in the
given string str1.
D. It returns the first index position of the last occurance of "save" in the
given string str1

8)What will following Python code return?

str1="Stack of books"
print(len(str1))

A. 13
B. 14
C. 15
D. 16

You might also like