Professional Documents
Culture Documents
Lab 4
Lab 4
AMAN LAB 4
March 18, 2024
[ ]: Dev JAIN(231031160010)
LAB-4(STRING)
PROGRAM-1: WAP to input three strings from a user using only one input() command amd print
the concatenated string
1
print(string[6:15])
print(string[-10:-1])
H e l l o
U n i Hello
Gurugram
Universit
PROGRAM 4: WAP to demonstrate the following function/methods
which operates on strings in python with suitable example :
len(),strip(),rstrip(),lstrip(),find(),index(),count(),replace(),split(),upper(),lower(),swapcase(),title(),capitalize(),startswith(),
2
print('12-',input12.swapcase())
#TITLE function
input13= "hello world"
print('13-',input13.title())
#capitalize function
input14="hello world"
print('14-',input14.capitalize())
#startswith function
input15="hello world" print('15-
',input15.startswith('k')) print('15-
',input15.startswith('h')) #endswith
function
input16="hello world" print('16-
',input16.endswith('f')) print('16-
',input16.endswith('world'))
1- 11
2- hello world
3- hello world
4- hello world
5- 7
6- 12
7- 3
8- hello gurugram
9- ['hello', 'world'] 10-
HELLO WORLD 11-
hello world
12- HELLO world
13- Hello World
14- Hello world
15- False
15- True
16- False
16- True
#PROGRAM 5: WAP to find the length of a string using 1)inbuilt function len() and 2) for loop
3
length of string by using function isd: 25
length of string by for loop is: 25
[ ]: