What is the correct way to create a string in Python?
A
str = 10 B
str = 'Hello' C
str = 10.5 D
str = True
Analysis & Theory
A string can be created by enclosing text in quotes, like `'Hello'`.
What will be the output of `len('Python')`?
A
5 B
6 C
7 D
Error
Analysis & Theory
`len()` returns the number of characters in a string. `'Python'` has 6 letters.
Which of the following will concatenate two strings in Python?
A
'Hello' + 'World' B
'Hello' * 'World' C
'Hello' - 'World' D
'Hello' / 'World'
Analysis & Theory
Use `+` to concatenate (join) two strings in Python.
What is the output of `'Python'[0]`?
A
P B
y C
0 D
n
Analysis & Theory
String indexing starts at 0, so `'Python'[0]` returns `'P'`.
Which method is used to convert a string to lowercase?
A
str.lowercase() B
str.down() C
lower() D
toLower()
Analysis & Theory
`lower()` converts all characters in the string to lowercase.
What is the result of `'Hello ' * 3`?
A
'HelloHelloHello' B
'Hello 3' C
'Hello Hello Hello ' D
'Hello Hello Hello'
Analysis & Theory
String repetition: `'Hello ' * 3` produces `'Hello Hello Hello'`.
Which of the following will return `True`?
A
'apple' == 'Apple' B
'abc' > 'def' C
'Python' != 'python' D
'A' > 'a'
Analysis & Theory
`'Python'` is not equal to `'python'` because string comparison is case-sensitive.
Which method is used to remove whitespace from both ends of a string?
A
trim() B
strip() C
clean() D
remove()
Analysis & Theory
`strip()` removes whitespace from both ends of a string.
What will `'Python'.upper()` return?
A
'PYTHON' B
'python' C
'Python' D
'Python.upper()'
Analysis & Theory
`upper()` converts all letters to uppercase.
Which of these checks if a substring exists in a string?
A
'in' keyword B
find() == True C
index() > 0 D
check()
Analysis & Theory
The `in` keyword is used to check if a substring exists in a string. Example: `'py' in 'python'`.