Python Unit - 3( a )String
Python Unit - 3( a )String
INTRODUCTION TO PYTHON
PROGRAMMING
BCA – II YEAR
IV SEMESTER
By:-
Vinita Thanvi
Assistant Professor
Lucky Institute of Professional Studies
Strings can be created using either single (‘) or double (“) quotes.
EXAMPLE:
s1 = ‘vinita'
s2 = “VINITA"
print(s1)
print(s2)
Output
vinita
VINITA
Slicing is a way to extract portion of a string by specifying the start and end
indexes.
The syntax for slicing is string[start:end], where start starting index and end
is stopping index (excluded).
String slicing allows you to extract a portion (substring) of the string using
the : operator.
The syntax :
string[start:end]
start: The starting index (inclusive).
end: The ending index (exclusive).
•Output
•Hello World
•Output
•Hello Hello Hello
Output
False
True
True By: Mrs. Vinita Thanvi Assistant Professor, IT Department, LIPS
String Manipulation Methods
In Python, strings are immutable sequences of characters, and there are many
built-in methods for manipulating and handling strings.
2.Write a Python function that takes a string and returns the string
with each word capitalized (capitalize every first letter of each
word).