Thanks to visit codestin.com
Credit goes to www.scribd.com

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

X TH Strings Worksheets With Answers

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)
41 views4 pages

X TH Strings Worksheets With Answers

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/ 4

Computer science half yearly worksheet with answers: Q17.

Q17. Write a code to assign a string "Hello World"' to a string variable named
Q1. What is String in Python? "str1". Ans. str1 = "Hello World"
Ans. A sequence of character which are enclosed in single(‘ ‘) or double (“”) Q18. Write the positive and negative index value of 'B' in the following
quotes is known as String. string. "Welcome to my Blog"
Q2. Is there any difference in ‘a’ or “a” in python? Ans. No Ans. positive index of B is = 14
Q3. Is there any difference between 1 or ‘1’ in python? Ans. Yes negative index of B is = -4
Q4. Python treats single quotes same as double quotes.(T/F) Ans. True Q19. What do you mean by concatenation of string?
Q5. A string with zero character is called __________ string. Ans. Empty Ans. Joining of two or more string is called concatenation. for example
Q6. Python does not support a character type.(T/F) Ans. True a = 'Amit'
Q7. Write a code to store following String in a variable named ‘str’. ‘This is b = 'Sethi'
Amit’s Blog’ c=a+b
Ans. str=”This is Amit\’s Blog” Q20. Which of the following is an example of string concatenation?
Q8. Write a code to create empty string 'str1' a. 6 + 3
Ans. str1 = ' ' b. '6' + '3' Ans. b and c
Q9. What do you mean by traversing a string? c. 'a' + 'b' + 'c'
Ans. Traversing a string means accessing all the elements of the string one by Q21. Write the code to join string 'str1' and 'str2' and store the result in
one by using index value. variable 'str3' Ans. str3 = str1 + str2
Q10 . What is the index value of first element of a string? Ans. 0 Q22. The ___________ operator join the string. Ans. +
Q11. What is the index value of last element of a string? Ans. -1 Q23. What type of error is shown by following code?
Q12. If the length of the string is 10 then what would be the positive index >>> 2 + '3' ans. TypeError
value of last element? Ans. 9 Q24. Which operator is used to replicate string? Ans. *
Q13. If the length of string is 9, what would be the index value of middle Q25. Write the output of the following.
element? Ans. 4 >>> 'A' * 3 Ans. AAA
Q14. Index value of a string can be in float. (T/F) Ans. False Q26. str="hello"
Q15. What type of error is returned by following statement, if the length of print(str[:3]) Ans : hel
string 'str1' is 10. >>> print(str1[13]) Ans. Index error Q27. print(“My”+’Blog’ * 2) Ans. MyBlogBlog
Q16. Write the output of the following: Q28. print(“My” *3 + “Blog” +’7′) Ans. MyMyMyBlog7
str1 = "Welcome to my Blog" ANS: Q29. for i in range(2,7,2):
a. print(str1[-1]) g print(i * '2') Ans.222222222222
A

b. print(str1[9]) o Q30. for i in range(3,12, 2): output A


A

print("a".upper()) A
A

Q31. ) s='Welcome to My Site https://csiplearninghub.com '


print(s.find('come')) Ans. Q40. Strings are mutable.(T/F) Ans. False
print(s.find('Z')) Q41. Write the output of the following
3
-1
Q32. Write the output of the following: Ans. >>>str1 = "Anita" Ans. TypeError
for i in range(2,5,2): @@ >>>str1[1] = 'm'
print(i * '@') @@@@ >>>print(str1)
Q33. 'in' or 'not in' are the _________ operator Ans. Membership Q42. Name any two built in function associated with string.
Q34. Write the output of the following Ans. len() and capitalize()
>>> 'h' in 'Hindi' False Q43. Which function of string return the numerical value? Ans. len()
>>>'i' in 'Hindi' True Q44. Q1. What is the value returned by find() function for an unsuccessful
Q35. Write the output of the following search? Ans. -1
>>>"string" in "substring" True Q45. isalpha() returns True if the string contains only alphabet.(T/F)
>>>"string" not in "substring" False Ans. True
Q36. Write the output of the following: Q46. Write the output of the following
>>>'tie' == 'ties' False str1 = "Amit"
>>>"Amit" != "Amitabh" True str2 = "My Blog"
>>>"amit" > "Amitabh" True str3 = "#blog"
Q37. Write the ASCII value of 'A' and 'a'. Ans. A = 65, a = 97 str4 = "My 1st Blog"
Q38. String Slicing is used to fetch substring from a string. (T/F) print(str1.isalpha())
Ans. True print(str2.isalpha())
Q39. Write the output of the following. print(str3.isalpha())
S = "Welcome to my Blog" print(str4.isalpha())
print(S[2 : 3])
print(S[2 : 10]) Specify the reason if any of the above print statement return False.
print(S[-2 : ])
print(S[-10 : -2 : 2]) Ans.
True
False : Return False as str2 conains spaces
Ans False : Returns False as str3 contain special character
l False : Return False as str4 contain digit and spaces.
lcome to Q47. Write the output of the following:
og >>>a = 123
t yB >>>b = "123"
>>>b.isdigit() True >>>print(s1.isspace()) True
>>>a.isdigit() Error >>>print(s2.isspace()) False
Q48. What is the difference between lower() and islower()? Q55. Define the following function with example
Ans. lower() function converts the given string in lowercase while islower() a. istitle()
check whether given string is in lowercase r not. b.swapcase()
Q49. Write the output of the following: Ans. istitle() - This function returns True if the string is in titlecase only
>>>s = "My blog" otherwise returns False.
>>>s.upper() MY BLOG for example s = "Welcome To My Blog"
>>>s.lower() my blog print(s.istitle())
>>>s.islower() False The above code returns True as the string 's' is in Title case.
>>>s.isupper() False swapcase() - This function converts all the lowercase characters to uppercase
>>>s.isalpha() False and vice versa
>>>s.isdigit() False for example s = "Welcome To My Blog"
Q50. What is lstrip () function in String? print(s.swapcase())
Ans. lstrip() function simply remove the spaces or specified characters from the Output: wELCOME tO mY bLOG
left of the string. Q56. . Write the output of the following:
Q51. Write the output of the following.(# represents the spaces) str1 = "Welcome to my Blog"
>>>str1 = "Welcome to my Blog" a. print(len(str1)) ans: . 18
>>>print(len(str1)) ans: 18 b. print(capitalize(str1)) Ans.. Welcome to my blog
>>>str2 = "###Welcome to my Blog"
>>>print(len(str2)) 21 Q57. Write the output of the following.
>>>print(len(str2.lstrip())) 18 >>>str1 = "Welcome to my Blog"
Q52. Write the output of the following.(# represents the spaces) >>>x = str1.split()
>>>str2 = "###Welcome to my Blog####" >>>print(x)
>>>print(len(str2)) ans: 25 Ans. ['welcome', 'to', 'my', 'blog']
>>>print(len(str2.strip())) 18 Q58. What is split() function in String?
>>>print(len(str2.rstrip())) 21 Ans. split() function split or break the string into multiple sub string at specified
Q53. isspace() returns True if the string contain only spaces (T/F) separator.
Ans. True Q59. Write the output of the following:
Q54. Write the output of the following a = "Mummy Papa Brother Sister Uncle"
>>>s1 = " " print(a.split())
>>>s2 = " Amit" ans: ['Mummy', 'Papa', 'Brother', 'Sister', 'Uncle']
print(a.split('e') Q67. Write a program to accept a string and display last three characters of
Ans. ['Mummy Papa Broth', 'r Sist', 'r Uncl', ''] the string.
Q60. Write a string function to replace all the word 'do' with 'done' in the Ans.
following string. str = input("Enter any String")
str1 = "I do you do and we all will do" print(str[-3 : : 1])
Ans. print(str1.replace('do','done'))
Q61. Write the output of the following. Q68. Write a program to accept a string in python and display the entire string
str1 = "I went to Auli" in lower case.
print(str1.replace("Auli", "Leh")) Ans.
Ans. I went to Leh str = input("Enter any String")
Q62. What is the purpose of find() function in string? print(str.lower())
Ans. find() function will return the first occurrence of substring in main string.
Q63. Write the output of the following: Q69. Write a program to accept a string and display first three characters of
str1 = "Welcome to my Blog" the string.
print(str1.find('o')) str = input("Enter any String")
Ans. 4 print(str[0:3])
Q70. Write a program to display each character of the following string in
Q64. Display string s in reverse order. separate line using 'for' loop.
print(s[: : -1]) str1 = Welcome to My Blog
Ans.
Q65 . Write a program to accept a string and display 20 times. str1 = "Welcome to my Blog"
str = input("Enter any String") for i in str1:
for i in range(20): print(i)
print(str) Q71. Match the Following answer:

Column-1 Column-2 Column-1 Column-2


Q66. Write a program to accept a string in python and display the entire string
Slicing string[range] + ‘x’ Slicing string[range]
in upper case.
Ans. Concatenation string[: – 1] Concatenation string1 + string2
str = input("Enter any String")
Repetition string[range] Repetition string * 7
print(str.upper())
Membership string1 + string2 Membership in, not in

Reverse in, not in Reverse string[: – 1]

You might also like