Exercise: Python

Questions for: Console Io

How can you check if a string ends with a specific suffix?
A:
str.ends_with(suffix)
B:
endswith(str, suffix)
C:
str.endswith(suffix)
D:
check_suffix(str, suffix)
Answer: C
To check if a string ends with a specific suffix in Python, you can use the endswith() method.
How can you remove leading and trailing whitespaces from a string?
A:
str.trim()
B:
trim(str)
C:
str.strip()
D:
remove_whitespaces(str)
Answer: C
The strip() method in Python is used to remove leading and trailing whitespaces from a string.
What will the end parameter in the print() function do?
A:
Sets the output separator between arguments
B:
Sets the end character at the end of the printed string
C:
Controls the formatting of the printed string
D:
Defines the width of the printed string
Answer: B
The end parameter in print() sets the end character that will be printed at the end of the string.
How can you convert a string to lowercase?
A:
str.lowercase()
B:
convert_lowercase(str)
C:
str.lower()
D:
lower(str)
Answer: C
The lower() method is used to convert a string to lowercase in Python.
How can you print the Unicode representation of a character?
A:
unicode_print('A')
B:
ord('A')
C:
print_unicode('A')
D:
unicode('A')
Answer: B
The ord() function in Python is used to get the Unicode code point of a character.
Ad Slot (Above Pagination)
Quiz