0% found this document useful (0 votes)
30 views13 pages

? Part 6 - Manipulating Strings - Questions 1-25

Uploaded by

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

? Part 6 - Manipulating Strings - Questions 1-25

Uploaded by

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

🟣 Part 6 – Manipulating Strings – Questions 1–25

1) What is a string in Python?


a) A numeric type
b) A sequence of characters
c) A boolean value
d) A list of integers

2) What operator is used to concatenate strings?


a) -
b) *
c) +
d) /

3) Which of these converts a string to uppercase?


a) upper()
b) lower()
c) strip()
d) find()

4) What does lower() do?


a) Converts to uppercase
b) Converts to lowercase
c) Splits the string
d) Removes whitespace

5) Which method removes leading and trailing spaces?


a) split()
b) strip()
c) join()
d) startswith()

6) What does split() return?


a) A list
b) An integer
c) A string
d) A boolean

7) What is the default separator in split()?


a) Space
b) Comma
c) Dot
d) Slash

8) What does join() do?


a) Joins list of strings into one string
b) Splits a string
c) Reverses a string
d) Capitalizes a string
9) Which method checks if a string starts with a substring?
a) endswith()
b) startswith()
c) find()
d) index()

10) What does endswith() check?


a) String is empty
b) String ends with substring
c) String contains substring
d) String starts with substring

11) What does find() return if substring not found?


a) 0
b) -1
c) None
d) True

12) What does replace() do?


a) Replaces parts of a string
b) Removes whitespace
c) Splits a string
d) Reverses a string

13) What does capitalize() do?


a) Makes all letters uppercase
b) Makes first letter uppercase
c) Reverses the string
d) Removes spaces

14) What does title() do?


a) Capitalizes every word
b) Converts to lowercase
c) Removes punctuation
d) Joins strings

15) Which method returns True if all characters are digits?


a) isalpha()
b) isalnum()
c) isdigit()
d) islower()

16) What does isalpha() test?


a) If all chars are digits
b) If all chars are letters
c) If string starts with A
d) If string is empty

17) What does islower() return if all letters are lowercase?


a) True
b) False
c) -1
d) 0

18) What does len() return for strings?


a) Length
b) Uppercase version
c) Lowercase version
d) List of chars

19) What is the result of 'Hello' + 'World'?


a) Hello World
b) HelloWorld
c) Hello+World
d) Error

20) What does strip('*') remove?


a) Only spaces
b) Leading and trailing *
c) All * anywhere
d) Nothing

21) What does 'abc'.upper() return?


a) abc
b) ABC
c) Abc
d) error

22) 'Hello'.lower() returns:


a) hello
b) HELLO
c) Hello
d) error

23) 'Python'.find('y') returns:


a) 0
b) 1
c) 2
d) -1

24) 'test'.startswith('t') returns:


a) True
b) False
c) -1
d) None

25) 'done'.endswith('e') returns:


a) True
b) False
c) -1
d) None
26) 'apple,banana,cherry'.split(',') returns:
a) ['apple banana cherry']
b) ['apple', 'banana', 'cherry']
c) ['apple,banana,cherry']
d) 'apple banana cherry'

27) ' '.join(['A', 'B', 'C']) returns:


a) 'ABC'
b) 'A B C'
c) ['A B C']
d) 'A, B, C'

28) What does 'data'.replace('a', 'o') return?


a) 'doto'
b) 'dotoa'
c) 'dato'
d) 'doto'

29) 'HELLO'.lower() returns:


a) hello
b) Hello
c) HELLO
d) error

30) 'Hi'.zfill(5) returns:


a) 'Hi'
b) '000Hi'
c) 'Hi000'
d) '0Hi0'

31) 'test'.find('x') returns:


a) -1
b) 0
c) None
d) Error

32) 'abc123'.isalnum() returns:


a) True
b) False
c) Error
d) None

33) ' spaced '.strip() returns:


a) 'spaced'
b) ' spaced'
c) 'spaced '
d) ' spaced '
34) What does rstrip() remove by default?
a) Leading spaces
b) Trailing spaces
c) All spaces
d) No spaces

35) 'abc'.ljust(5, '*') returns:


a) 'abc'
b) 'abc**'
c) '**abc'
d) 'abc'

36) '123'.isnumeric() returns:


a) True
b) False
c) None
d) Error

37) 'Test String'.istitle() returns:


a) True
b) False
c) None
d) Error

38) What does 'hello'.capitalize() return?


a) Hello
b) HELLO
c) hello
d) hELLO

39) 'ABCD'.swapcase() returns:


a) abcd
b) ABCD
c) AbCd
d) error

40) 'Python'.center(10, '-') returns:


a) '--Python--'
b) 'Python----'
c) '----Python'
d) '--Python---'

41) 'text'.count('t') returns:


a) 2
b) 1
c) 0
d) 4

42) 'abc'.encode() returns:


a) bytes object
b) integer
c) list
d) string

43) 'hello world'.title() returns:


a) Hello World
b) Hello world
c) HELLO WORLD
d) hello World

44) '123'.isdigit() returns:


a) True
b) False
c) None
d) Error

45) 'File.TXT'.endswith('.txt') returns:


a) True
b) False
c) None
d) Error

46) 'sample'.startswith('s') returns:


a) True
b) False
c) None
d) Error

47) 'repeat repeat'.count('repeat') returns:


a) 2
b) 1
c) 0
d) 3

48) 'Test'.isupper() returns:


a) False
b) True
c) None
d) Error

49) 'LOWER'.islower() returns:


a) False
b) True
c) None
d) Error

50) 'Line\nBreak'.splitlines() returns:


a) ['Line', 'Break']
b) ['Line Break']
c) 'Line Break'
d) ['Line\nBreak']
51) 'python'.rjust(8, '*') returns:
a) 'python'
b) 'python'
c) 'python'
d) 'python'

52) 'DATA'.lower() returns:


a) data
b) DATA
c) Data
d) dATA

53) ' '.isspace() returns:


a) True
b) False
c) None
d) Error

54) 'abc'.find('b') returns:


a) 0
b) 1
c) 2
d) -1

55) 'abc'.index('c') returns:


a) 0
b) 1
c) 2
d) -1

56) 'Alpha Beta Gamma'.split() returns:


a) ['Alpha Beta Gamma']
b) ['Alpha', 'Beta', 'Gamma']
c) ('Alpha', 'Beta', 'Gamma')
d) 'Alpha Beta Gamma'

57) 'hello world'.replace('world', 'Python') returns:


a) hello Python
b) hello world
c) Hello Python
d) Python world

58) 'banana'.count('a') returns:


a) 2
b) 3
c) 4
d) 1
59) 'Python3'.isalnum() returns:
a) True
b) False
c) None
d) Error

60) 'Test123'.isalpha() returns:


a) True
b) False
c) None
d) Error

61) '1234'.isdecimal() returns:


a) True
b) False
c) None
d) Error

62) 'UPPERCASE'.isupper() returns:


a) True
b) False
c) None
d) Error

63) 'lowercase'.islower() returns:


a) True
b) False
c) None
d) Error

64) 'Test'.center(8) returns:


a) ' Test '
b) ' Test '
c) ' Test '
d) ' Test '

65) 'text'.zfill(6) returns:


a) '00text'
b) '000text'
c) 'text00'
d) 'text000'

66) 'Python'.lstrip('Py') returns:


a) 'thon'
b) 'Python'
c) 'hon'
d) 'on'

67) 'A,B,C'.split(',') returns:


a) ['A', 'B', 'C']
b) ('A', 'B', 'C')
c) 'A B C'
d) ['A B C']

68) 'data'.swapcase() returns:


a) DATA
b) Data
c) DATA
d) DATA

69) 'Python'.find('x') returns:


a) -1
b) 0
c) None
d) 1

70) 'Hello'.rjust(7) returns:


a) ' Hello'
b) ' Hello '
c) 'Hello '
d) 'Hello'

71) 'abc123'.isalnum() returns:


a) True
b) False
c) None
d) Error

72) 'abc'.isidentifier() returns:


a) True
b) False
c) None
d) Error

73) '1variable'.isidentifier() returns:


a) True
b) False
c) None
d) Error

74) 'string with\nlinebreak'.splitlines() returns:


a) ['string with', 'linebreak']
b) ['string with linebreak']
c) 'string with linebreak'
d) ['string with\nlinebreak']

75) 'abc'.rjust(5) returns:


a) ' abc'
b) 'abc '
c) ' abc '
d) 'abc'
76) 'HELLO'.swapcase() returns:
a) hello
b) Hello
c) hELLO
d) HELLO

77) 'word'.center(9, '-') returns:


a) '---word--'
b) '--word---'
c) '--word--'
d) '-word---'

78) 'SampleText'.partition('Text') returns:


a) ('Sample', 'Text', '')
b) ('Sample', 'Text', 'Text')
c) ('Sample', 'Text', '')
d) ('SampleText', '', '')

79) 'data'.rpartition('a') returns:


a) ('dat', 'a', '')
b) ('da', 't', 'a')
c) ('dat', 'a', '')
d) ('da', 'a', 'ta')

80) 'banana'.count('na') returns:


a) 1
b) 2
c) 3
d) 4

81) 'Python'.endswith('on') returns:


a) True
b) False
c) None
d) Error

82) 'Python Programming'.startswith('Python') returns:


a) True
b) False
c) None
d) Error

83) 'test'.ljust(6, '_') returns:


a) 'test__'
b) '_test'
c) 'test'
d) 'test'
84) 'abc'.rjust(6, '.') returns:
a) '...abc'
b) 'abc...'
c) '.abc.'
d) 'abc'

85) 'hello'.capitalize() returns:


a) Hello
b) HELLO
c) hello
d) hELLO

86) '123abc'.isalnum() returns:


a) True
b) False
c) None
d) Error

87) 'abc'.isalpha() returns:


a) True
b) False
c) None
d) Error

88) '123'.isdigit() returns:


a) True
b) False
c) None
d) Error

89) 'abc123'.isdecimal() returns:


a) False
b) True
c) None
d) Error

90) 'one\ntwo\nthree'.splitlines() returns:


a) ['one', 'two', 'three']
b) ['one two three']
c) 'one two three'
d) ['one\ntwo\nthree']

91) ' trim '.strip() returns:


a) 'trim'
b) ' trim'
c) 'trim '
d) ' trim'

92) 'Python3'.isalnum() returns:


a) True
b) False
c) None
d) Error

93) 'Var123'.isidentifier() returns:


a) True
b) False
c) None
d) Error

94) 'for'.isidentifier() returns:


a) True
b) False
c) None
d) Error

95) 'test string'.title() returns:


a) Test String
b) Test string
c) TEST STRING
d) test String

96) 'string'.zfill(8) returns:


a) '00string'
b) '000string'
c) 'string00'
d) 'string000'

97) 'ABC'.lower() returns:


a) abc
b) ABC
c) Abc
d) error

98) 'abc'.upper() returns:


a) ABC
b) abc
c) Abc
d) error

99) '123'.isnumeric() returns:


a) True
b) False
c) None
d) Error

100) 'Python'.find('P') returns:


a) 0
b) 1
c) -1
d) None

You might also like