Computer Science
What happens when from a string slice you skip the start and/or end values of the slice?
Python String Manipulation
19 Likes
Answer
If start value is skipped, it is assumed as 0 i.e. the slice begins from the start of the string.
If end value is skipped, it is assumed as the last index of the string i.e. the slice extends till the end of the string.
Answered By
11 Likes
Related Questions
Given a string S = "CARPE DIEM". If n is length/2 (length is the length of the given string), then what would following return?
(a) S[: n]
(b) S[n :]
(c) S[n : n]
(d) S[1 : n]
(e) S[n : length - 1]From the string S = "CARPE DIEM", which ranges return "DIE" and "CAR"?
What would the following expressions return?
- "Hello World".upper( ).lower( )
- "Hello World".lower( ).upper( )
- "Hello World".find("Wor", 1, 6)
- "Hello World".find("Wor")
- "Hello World".find("wor")
- "Hello World".isalpha( )
- "Hello World".isalnum( )
- "1234".isdigit( )
- "123FGH".isdigit( )
Which functions would you choose to use to remove leading and trailing white spaces from a given string?