Python cut the string to length | Example code
Use syntax string[x:y] to slice a string starting from index x up to but not including the character at index y. If you want only… Read More »Python cut the string to length | Example code
Use syntax string[x:y] to slice a string starting from index x up to but not including the character at index y. If you want only… Read More »Python cut the string to length | Example code
Use the Python rfind() method to find the last occurrence in the string. This function returns a “-1” if a substring (char) is not found.… Read More »Python finds the last occurrence in string | Example code
Use the split() method to slice string by a character in Python. The split() method splits a string into a list. You have to provide… Read More »Python slice string by character | Example code
Using a negative number as an index in the slice method is called Negative slicing in Python. It returns the nth element from the right-hand… Read More »Negative slicing in Python | Example code
Doing slicing will extract part of a string in Python. Use square-bracket syntax with the starting position of the piece we want, but also where… Read More »Python extract part of a string | Example code
The sorted() function sorts the list of elements in a specific order and returns it as a list. Using sorted function with reverse Parameters you… Read More »Python sorted reverse Parameters | Example code
To reverse for loop in Python just need to read the last element first and then the last but one and so on till the… Read More »Reverse for loop in Python | Example code
Use re.sub() method of the re module to replace the string that matches the RegEx (regular expression) in Python. A Regular Expression (RE) is a… Read More »Python RegEx find and replace | Example code
Python provides a special 3 methods to remove whitespace from a string (characters) lstrip() – Remove spaces to the left of the string rstrip() –… Read More »How to strip multiple characters Python | Example code
Using re.sub() or split() + join() method to remove extra spaces between words in Python. Python remove extra spaces between words Example Simple example code.… Read More »Python remove extra spaces between words | Example code