[go: up one dir, main page]

0% found this document useful (0 votes)
17 views2 pages

String Manipulation Practice Sheet

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

String Manipulation Practice Sheet

th ank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Strings

Practice Sheet -6 (Output Findout) 12. s='My'


s1='Blog'
1. Find errors s2=s[:1]+s1[len(s1)-1:]
a = input(Enter your name) print(s2)
b = input("Enter any number")
13. print(“My”+’Blog’ * 2)
2. Find errors:
a = input("Enter your name" 14. print(“My” *3 + “Blog” +’7′)
Print(Your name is, a)
15. for i in range(2,7,2):
3. >>> a, b = 2, 6 print(i * '2')
>>> a, b, b = a+b, 2, 3
>>> print(a,b) 16. for i in range(3,12, 2):
print("a".upper())
4. >>> a = 5
>>> b = "Amit" 17. for i in range(3,12,13):
>>> print(a + b) print("a".upper)

5. >>> a =3 18. s='Welcome to India'


>>> b =4 print(s.find('come'))
>>> print(a + b%2 + a**2) print(s.find('o'))
print(s.find('o', 10, 20))
6. str1 = "Welcome to my blog" print(s.find('o', 5, 10))
str2 = "Welcome to my \n Blog"
print(str1) 19. str1 = "Welcome to my Blog"
print(str2) print(str1[-1])
print(str1[9])
7. str1 = "Welcome \tto my Blog"
str2 = "Welcome to\n my \tBlog 20. str1 = "Welcome to my Blog"
print(str1) for i in str1:
print(str2) print(i)
print(i, end = '#')
8. str1 = “”” Welcome to my print(i, end =' ')
blog.
This is for 21. str1 = "Amit"
Class X””” for i in str1:
print(str1) print(i)
print(i, end =' ')
9. str="hello"
print(str[:3]) 22. str1 = "Welcome to my Blog"
for i in str1:
10. str='MyBLog' print(i)
a=' ' print(i, end =' ')
for i in range(len(str)): print(i, end = '#')
print("=",i * str[i])
23. >>> 'h' in 'Hindi'
11. s='My' >>>'i' in 'Hindi'
s1='Blog'
s2=s[:1]+s1[len(s1)-1:] 24. for i in "Amit":
print(s2) print(i in "Amit")
25. for i in range(2,5,2): 35.
print(i * '@')
>>>str2 = "###Welcome to my Blog####"
26. for i in "Amit": >>>print(len(str2))
print(i in "Amit") >>>print(len(str2.strip()))
>>>print(len(str2.rstrip()))
27. >>>"string" in "substring"
>>>"string" not in "substring" 36. >>> str1 = "Welcome to my Blog"
>>> print(str1.rstrip('og'))
28. >>>'tie' == 'ties' >>> print(str1.lstrip('We'))
>>>"Amit" != "Amitabh" >>> print(str1.strip('Welog))
>>>"amit" > "Amitabh"
37. >>> str1 = "Welcome to my Blog"
29. S = "Welcome to my Blog" >>>print(len(str1.rstrip('og')))
print(S[2 : 3]) >>>print(len(str1.lstrip('We')))
print(S[2 : 10]) >>>print(len(str1.strip('Welog)))
print(S[-2 : ])
print(S[-10 : -2 : 2]) 38. >>>s1 = " "
>>>s2 = " Amit"
30. >>>str1 = "Anita" >>>print(s1.isspace())
>>>str1[1] = 'm' >>>print(s2.isspace())
>>>print(str1)
39. >>>str1 = "Welcome to my Blog"
31. str1 = "Amit" >>>print(len(str1))
str2 = "My Blog" >>>print(capitalize(str1))
str3 = "#blog"
str4 = "My 1st Blog" 40. >>>str1 = "Welcome to my Blog"
print(str1.isalpha()) >>>x = str1.split()
print(str2.isalpha()) >>>print(x)
print(str3.isalpha())
print(str4.isalpha()) 41.
a = "Mummy?Papa?Brother?Sister?Uncle"
32. >>a = 123 print(a.split())
>>>b = "123" print(a.split('?')
>>>b.isdigit() print(a.split('?',1)
>>>a.isdigit() print(a.split('?',3)
print(a.split('?',10)
33. >>>s = "My blog" print(a.split('?',-1)
>>>s.upper()
>>>s.lower() 42. str1 = "I went to Auli"
>>>s.islower() print(str1.replace("Auli", "Leh"))
>>>s.isupper() print(str1)
>>>s.isalpha()
>>>s.isdigit() 43. str1 = "Welcome to my Blog"
print(str1.find('o'))
34. >>>str1 = "Welcome to my Blog" print(str1.find('o',3))
>>>print(len(str1)) print(str1.find('o',7))
>>>str2 = "###Welcome to my Blog" print(str1.find('o',7,10))
>>>print(len(str2))
>>>print(len(str2.lstrip()))

You might also like