Professional Documents
Culture Documents
U18CSI2201 - Strings 1
U18CSI2201 - Strings 1
U18CSI2201 - Strings 1
UNIT – III
print("uppercase",u)
print("Lowercase",c)
Solution for Ex.2
def modify(string):
final_odd = ""
final_even="" Output:
for i in range(len(string)):
if i % 2 ==0: Enter string: kumaraguru
final_odd = final_odd+string[i]
else: String in odd and even index position is:
final_even=final_even+string[i] ('kmrgr', 'uaauu')
string=input("Enter string:")
print("String in odd and even index position is:")
print(modify(string))
# count the number of vowels
# Method 2
y=x.count('a') + x.count('e') + x.count('i') + x.count('o') +
x.count('u')
print(y)
# count the number of digits, alphabet, special char, word and sentence in the given paragraph
x = input("Enter the string ")
count,c,c1,p=0,0,0,0
for i in x:
if i.isalpha():
count= count + 1
elif i.isdigit():
c=c+1
elif i==".":
p=p+1
else:
c1 = c1 + 1
word = len(x.split())
print("Char",count)
print("Digit = ",c)
print("Spl=",c1)
print("Para",p)
print("word",word)
Quiz
1.What will be the output of the following:
s1= “Welcome to java programming”
s2=s1.replace(“java”,”python”)
print(s2)
a. Welcome to java programming
b. Welcome to python programming
c. Welcome to java python programming
d. None of the above
2. What will be the output of the following:
str1=“Hello”
str2=str1[:-1]
print(str2)
a.olle
b.Hello
c.el
d.Hell
3.What will be the output of the following:
str1=“Python Programming”
str1[0]=“J”
print(str1)
a. Jython Programming
b. Jython Jrogramming
c. Jython
d. Error
4.What will be the output of the following:
S=“Programming”
For char in S:
print(char, end=“ ”)
a.Programming
b.P r o g r a m m i n g
c.Error
d.None of the above
Summary
Creating String
Indexing strings
Slicing strings
Immutable strings
String operations