0% found this document useful (0 votes)
49 views

10AI Rev String

Uploaded by

bruhanth2008
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)
49 views

10AI Rev String

Uploaded by

bruhanth2008
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/ 20

1

2EZ.IN

Grade 10-AI Worksheet


String functions

1. What does the len() function do in Python?


A) Returns the length of the string
B) Returns the number of words in the string
C) Converts the string to lowercase
D) Reverses the string
2. Which method will convert all characters of a string to
uppercase in Python?
A) upper()
B) lower()
C) capitalize()
D) title()
3. What is the output of str[1:5] if str = 'Programming'?
A) Prog
B) ramm
C) roga
D) rogr
4. Which method is used to join the elements of a list into a
string in Python?
A) join()
B) concatenate()
C) append()
D) extend()
5. What does the find() function do in Python?
A) Finds the last occurrence of a substring
B) Finds the first occurrence of a substring
C) Removes the first character of a string
D) Returns the length of a string
6. What will be the output of "Hello".lower()?
2
2EZ.IN

A) HELLO
B) hello
C) HeLLo
D) hellO
7. In Python, what does str.strip() do?
A) Removes all whitespace from the string
B) Removes leading and trailing whitespaces
C) Converts the string to lowercase
D) Replaces spaces with underscores
8. How do you check if a string starts with a certain substring
in Python?
A) startswith()
B) endswith()
C) find()
D) index()
9. Which of the following will correctly split a string at every
occurrence of a space character?
A) str.split(",")
B) str.split(" ")
C) str.split("-")
D) str.split()
10. Which method will return True if a string contains only
alphabetic characters?
A) isnumeric()
B) isdigit()
C) isalnum()
D) isalpha()

11. What is the default separator when using the split()


method in Python?
A) ,
B) ;
3
2EZ.IN

C) Space
D) Tab
12. What does the capitalize() method do in Python?
A) Converts the entire string to uppercase
B) Converts the first character to uppercase
C) Capitalizes every word in the string
D) Converts the entire string to lowercase
13. How do you check if a string ends with a specific substring
in Python?
A) startswith()
B) endswith()
C) find()
D) index()
14. What will the output of "hello".title() be?
A) hello
B) HELLO
C) Hello
D) hELLO
15. In Python, how do you count the occurrences of a
substring in a string?
A) find()
B) index()
C) count()
D) search()
16. Which method is used to replace a substring with another
substring in Python?
A) sub()
B) replace()
C) switch()
D) substitute()
17. What will the str.isdigit() method return if str = "123abc"?
A) True
B) False
4
2EZ.IN

C) Error
D) None
18. What is the output of the expression "Python".find('t')?
A) 3
B) 2
C) 1
D) 4
19. Which of the following is the correct way to check if a
string consists only of whitespace characters?
A) str.isdigit()
B) str.isspace()
C) str.isalpha()
D) str.isalnum()
20. What will the output of "abcd".index('b') be?
A) 0
B) 1
C) 2
D) 3

21. What will "Python".replace("P", "J") return?


A) Jython
B) JythonP
C) PythonJ
D) PytJon
22. How can you convert a string to lowercase in Python?
A) str.lower()
B) str.capitalize()
C) str.upper()
D) str.strip()
23. What does "Python".islower() return?
A) True
B) False
5
2EZ.IN

C) None
D) Error
24. Which method would you use to concatenate two strings
with a space in between?
A) concatenate()
B) append()
C) join()
D) +
25. Which method in Python checks if all characters in a string
are uppercase?
A) isupper()
B) islower()
C) upper()
D) lower()
26. What is the result of "abcde".count('e')?
A) 1
B) 2
C) 0
D) 4
27. What does "hello".center(10) do in Python?
A) Pads the string with whitespace to make the total length 10
B) Removes spaces from both ends of the string
C) Splits the string into 10 equal parts
D) Returns the middle 10 characters of the string
28. Which method is used to check whether a string contains
only alphanumeric characters?
A) isnumeric()
B) isalnum()
C) isalpha()
D) isdigit()
29. What does "abcd".endswith("cd") return?
A) True
B) False
6
2EZ.IN

C) None
D) Error
30. Which of the following methods reverses a string in
Python?
A) reverse()
B) [::-1]
C) str.reverse()
D) str[::-2]

31. What will be the output of "Python".swapcase()?


A) python
B) PYTHON
C) pYTHON
D) PytHon
32. How do you get the ASCII value of a character in Python?
A) ord()
B) char()
C) ascii()
D) ord(char)
33. Which method in Python is used to remove a specific
character from a string?
A) delete()
B) remove()
C) replace()
D) strip()
34. What will the output of "Hello World".split() be?
A) ['Hello', 'World']
B) ['HelloWorld']
C) ['Hello', '', 'World']
D) ['Hello', ' ', 'World']
35. What is the output of "Hello".rfind('l')?
A) 2
B) 3
7
2EZ.IN

C) 4
D) 5
36. What does "Hello World".count('o') return?
A) 0
B) 1
C) 2
D) 3
37. What does "HELLO".isupper() return?
A) True
B) False
C) None
D) Error
38. How do you convert an integer into a string in Python?
A) str()
B) int()
C) float()
D) str(int)
39. Which method is used to convert the first character of
each word to uppercase?
A) capitalize()
B) upper()
C) title()
D) lower()
40. What does "apple".startswith('a') return?
A) True
B) False
C) None
D) Error

41. What does "banana".count('a') return?


A) 2
B) 3
8
2EZ.IN

C) 4
D) 5
42. How can you replace all occurrences of a character in a
string?
A) str.remove()
B) str.replace()
C) str.split()
D) str.join()
43. What will "Hello World".upper() return?
A) HELLO WORLD
B) hello world
C) Hello world
D) hello World
44. Which method converts a string to lowercase?
A) lower()
B) capitalize()
C) upper()
D) strip()
45. What will "123".isdigit() return?
A) True
B) False
C) None
D) Error
46. What is the output of "test".capitalize()?
A) Test
B) TEST
C) test
D) teSt
47. Which method is used to return a string with leading
zeros?
A) strip()
B) ljust()
9
2EZ.IN

C) zfill()
D) rjust()
48. What does "welcome".startswith("wel") return?
A) True
B) False
C) None
D) Error
49. What will be the output of "abcd".find('z')?
A) -1
B) 0
C) None
D) Error
50. What does "Good".islower() return?
A) True
B) False
C) None
D) Error

51. Which method is used to remove all leading spaces from a


string?
A) rstrip()
B) lstrip()
C) strip()
D) remove()
52. What will "abcde".find('b', 2) return?
A) -1
B) 1
C) 0
D) 2
53. Which method is used to check if all characters in a string
are alphabetic?
A) isalnum()
B) isalpha()
10
2EZ.IN

C) isdigit()
D) isspace()
54. What is the output of "abcd".rindex('b')?
A) 0
B) 1
C) 2
D) 3
55. What does "Hello World".replace("o", "a") return?
A) Hella Warld
B) Hella World
C) Helloo World
D) Hella Waalrd
56. What will "test".endswith('t') return?
A) True
B) False
C) None
D) Error
57. What is the output of "python".islower()?
A) True
B) False
C) None
D) Error
58. Which method removes the trailing characters from a
string?
A) rstrip()
B) lstrip()
C) strip()
D) remove()
59. What does "apple".rindex('p') return?
A) 1
B) 2
C) 0
D) -1
11
2EZ.IN

60. Which method can be used to check if a string contains


only numeric characters?
A) isalnum()
B) isdigit()
C) isalpha()
D) isspace()

61. What is the result of "python".count('y')?


A) 1
B) 2
C) 0
D) 3
62. How do you check if a string is entirely uppercase in
Python?
A) isupper()
B) islower()
C) upper()
D) lower()
63. What is the output of "abcde".startswith('abc')?
A) True
B) False
C) None
D) Error
64. What will "apple".rfind('a') return?
A) 1
B) 2
C) 3
D) 0
65. What is the output of "Python3".isalnum()?
A) True
B) False
C) None
D) Error
12
2EZ.IN

66. Which method converts a string to title case?


A) title()
B) capitalize()
C) lower()
D) upper()
67. What does "hello".lstrip() do?
A) Removes leading whitespace
B) Removes trailing whitespace
C) Removes both leading and trailing whitespace
D) Removes all whitespace
68. What is the result of "python".isalpha()?
A) True
B) False
C) None
D) Error
69. What will be the output of "python".index('t')?
A) 2
B) 3
C) 4
D) 1
70. What does "hello".rjust(10) return?
A) hello
B) hello
C) hel lo
D) helhello

71. What will "hello".count('l') return?


A) 1
B) 2
C) 3
D) 4
72. How can you reverse a string in Python?
13
2EZ.IN

A) str.reverse()
B) [::-1]
C) reverse()
D) rev()
73. Which of the following returns True if the string is a valid
identifier?
A) isalpha()
B) isalnum()
C) isidentifier()
D) isdigit()
74. What will "apple".find('z') return?
A) -1
B) 1
C) 0
D) None
75. How do you check if a string contains only whitespace
characters?
A) isspace()
B) isalnum()
C) isalpha()
D) isdigit()
76. What will be the result of "hello".ljust(10)?
A) hello
B) hello
C) hellohello
D) hello
77. Which method would you use to pad a string with zeros
on the left?
A) zfill()
B) rjust()
C) ljust()
D) pad()
78. What is the output of "Python".islower()?
14
2EZ.IN

A) True
B) False
C) None
D) Error
79. What will be the result of "hello world".find('l')?
A) 2
B) 3
C) 4
D) None
80. What does "python3".isdigit() return?
A) True
B) False
C) None
D) Error

81. Which method returns a string with both leading and


trailing spaces removed?
A) strip()
B) rstrip()
C) lstrip()
D) trim()
82. What is the result of "12345".rjust(10)?
A) 12345
B) 12345
C) 1234512345
D) 12345
83. How do you check if a string is entirely lowercase?
A) islower()
B) isupper()
C) lower()
D) upper()
84. What is the output of "python".title()?
15
2EZ.IN

A) Python
B) PYTHON
C) pYTHON
D) Python Python
85. What will "python".replace('p', 'b') return?
A) bython
B) pythonb
C) bythonp
D) pybhon
86. What does "python".center(10) return?
A) python
B) python
C) python
D) python
87. How do you check if a string contains only digits in
Python?
A) isdigit()
B) isalnum()
C) isnumeric()
D) isalpha()
88. What is the result of "Python".endswith('n')?
A) True
B) False
C) None
D) Error
89. What will "hello world".rindex('o') return?
A) 4
B) 7
C) 5
D) 10
90. What does "Python".zfill(10) return?
A) 0000Python
B) 000Python
16
2EZ.IN

C) Python0000
D) PythonPython

91. Which method can be used to pad a string with spaces on


the right?
A) rjust()
B) ljust()
C) center()
D) zfill()
92. What will "python".find('p') return?
A) 0
B) 1
C) 2
D) None
93. What does "python".islower() return?
A) True
B) False
C) None
D) Error
94. What is the result of "python".upper()?
A) PYTHON
B) Python
C) python
D) PyThon
95. What will "python".startswith('p') return?
A) True
B) False
C) None
D) Error
96. Which method converts the first letter of each word to
uppercase in Python?
A) capitalize()
B) upper()
17
2EZ.IN

C) title()
D) lower()
97. What will be the result of "python".index('h')?
A) 3
B) 2
C) 4
D) 5
98. What is the output of "apple".find('p')?
A) 0
B) 1
C) 2
D) None
99. What will "abcde".replace('a', 'z') return?
A) zbcde
B) azcde
C) abzde
D) abcze
100. What does "hello".swapcase() return?
A) HELLO
B) hELLO
C) Hello
D) HeLLo

Answers:
1. A
2. A
3. B
4. A
5. B
6. B
7. B
8. A
9. B
18
2EZ.IN

10. D
11. C
12. B
13. B
14. C
15. C
16. B
17. B
18. A
19. B
20. B
21. A
22. A
23. B
24. D
25. A
26. A
27. A
28. B
29. A
30. B
31. C
32. A
33. C
34. A
35. C
36. C
37. A
38. A
39. C
40. A
41. B
42. B
19
2EZ.IN

43. A
44. A
45. A
46. A
47. C
48. A
49. A
50. B
51. B
52. A
53. B
54. B
55. A
56. A
57. A
58. A
59. B
60. B
61. A
62. A
63. A
64. D
65. A
66. A
67. A
68. A
69. B
70. A
71. C
72. B
73. C
74. A
75. A
20
2EZ.IN

76. A
77. A
78. B
79. C
80. B
81. A
82. A
83. A
84. A
85. A
86. A
87. A
88. A
89. B
90. A
91. B
92. A
93. A
94. A
95. A
96. C
97. A
98. B
99. A
100. B

You might also like