Professional Documents
Culture Documents
Coding Set 2 Questions
Coding Set 2 Questions
Coding Set 2 Questions
1. What is the result of the expression `"Hello" + b) Using triple double-quotes: """..."""
"World"` in Python?
c) Using backslashes at the end of each line: \
a) "HelloWorld"
d) Using parentheses: (...)
b) "Hello World"
7. What method can be used to convert a string
c) "Hello" + " " + "World" to all uppercase letters in Python?
d) Error a) `to_upper()`
a) Mutable c) `uppercase()`
b) Immutable d) `capitalize()`
3. Which method is used to find the length of a 8. Which of the following statements is true
string in Python? regarding string indexing in Python?
4. How can you check if a string `my_string` 9. What is the output of `len("Python")`?
starts with the substring `"Hello"`?
a) 5
a) `my_string.starts_with("Hello")`
b) 6
b) `my_string.startswith("Hello")`
c) 7
c) `my_string.begins_with("Hello")`
d) 8
d) `my_string.starts("Hello")`
10. Which escape sequence is used to represent a
5. What will `str(123)` return? newline character in a string?
a) "123" a) \n
b) 123 b) \t
c) "0b1111011" c) \\
d) Error d) \r
b) `trim()` a) "Py"
c) `remove_whitespace()` b) "yth"
d) `clear()` c) "tho"
b) `search()` a) `replace()`
c) `index()` b) `sub()`
d) `locate()` c) `swap()`
a) Splits a string into a list of substrings based 20. Which of the following methods can be used
on a delimiter to check if a string ends with a specific suffix?
JAVA MCQ QUESTIONS: 5. How can you find the length of a string in
Java?
1. In Java, which class is used to represent
strings? a) `str.length()`
a) String b) `str.size()`
b) StringBuilder c) `str.length`
c) StringBuffer d) `str.size`
c) `String` is a final class, while 7. In Java, can you change the characters of a
`StringBuilder` is not. `String` after it has been created?
b) No
3. Which method is used to compare two strings 8. What is the default value for a `String`
in Java for their content? variable in Java if it is not initialized?
a) `equals()` a) null
b) `compareTo()` b) ""
c) `compare()` c) "null"
d) `contentEquals()` d) "undefined"
a) "HelloWorld" b) `slice()`
c) "WorldHello" d) `substring()`
10. How do you check if a string contains a d) `replaceLast()`
specific substring in Java?
15. How do you concatenate two strings in Java?
a) `str.contains(substring)`
a) Using the `&` operator
b) `str.indexOf(substring) != -1`
b) Using the `+` operator
c) `str.includes(substring)`
c) Using the `concat()` method
d) `str.find(substring)`
d) Using the `join()` method
11. What is the result of `"Java".charAt(2)`?
16. What is the output of
a) 'J' `"java".toUpperCase()`?
b) 'a' a) "java"
c) 'v' b) "JAVA"
d) 'a' c) "Java"
b) `beginWith()` a) `str.ends_with(suffix)`
c) `startWith()` b) `str.is_endswith(suffix)`
d) `prefixWith()` c) `str.endsWith(suffix)`
b) `intValue.toString()` a) `trim()`
c) `intValue.to_string()` b) `strip()`
d) `toString(intValue)` c) `clean()`
a) `count()`
b) `find()`
c) `indexOf()`
d) `matches()`
user)
year or not