Splitting
Splits a string into a list at every specified separator. If no separator is specified, default separator is whitespace.
Code
Output
Multiple WhiteSpaces
Multiple whitespaces are considered as single when splitting.
Code
Output
New line
Code
Output
Using Separator
Breaks up a string at the specified separator.
Example -1
Code
Output
Example -2
Code
Output
Space as Separator
Code
Output
String as Separator
Example - 1
Code
Output
Example - 2
Output
Joining
Takes all the items in a sequence of strings and joins them into one string.
Code
Output
Joining Non String Values
Sequence should not contain any non-string values.
Code
Output
Negative Indexing
Using a negative index returns the nth item from the end of list.
Last item in the list can be accessed with index
Reversing a List
Code
Output
Accessing List Items
Example-1
Code
Output
Example-2
Code
Output
Slicing With Negative Index
You can also specify negative indices while slicing a List.
Code
Output
Out of Bounds Index
While slicing, Index can go out of bounds.
Code
Output
Negative Step Size
Negative Step determines the decrement between each index for slicing.
Start index should be greater than the end index in this case
- start > end
Negative Step Size Examples
Example - 1
Code
Output
Example - 2
Negative step requires the start to be greater than end.
Code
Output
Reversing a List
Output
Reversing a String
Code
Output
Negative Step Size - Strings
Code
Output
Indexing & Slicing - Strings
Example - 1
Code
Output
Example - 2