Python String
- 27 October
Add Spaces Between Characters in Python
A string is the generic data type that is offered by Python to store and represent a series of Unicode characters. There might be a need to add a space between all characters of a given string. This tutorial focuses on and demonstrates the different ways available to add spaces between characters in Python. The […]
- 25 December
Encode String to UTF-8 in Python
The UTF-8 encoding is used by default in Python and represents 8-bit Unicode values. The upgrade to Python 3 saw a major change in using ASCII characters to Unicode characters by default for strings. Encode String to UTF-8 in Python This tutorial will demonstrate how to encode string to UTF-8 in Python. Using the encode() […]
- 23 December
How To Do Line Continuation in Python
Using Backslash (\) Operator We can use \ operator for line continuation in string and number expression as follows. Line Continuation in String To do line continuation in Python Strings: Use the backslash operator to do line continuation for writing strings in Python. [crayon-63bb74d38a0eb425880667/] [crayon-63bb74d38a0ef318106207/] A backslash (\) is an explicit line break operator in […]
- 16 December
Convert List to Comma Separated String in Python
Use .join() Method To convert a list to a comma separated string in Python, use the .join() method. join() method takes all elements in an iterable and joins them into one string with delimiter as separator. [crayon-63bb74d38a20e244406318/] [crayon-63bb74d38a211627875792/] First, we created a list having string-type elements and named that list list_of_strings. Next, we used the […]
- 09 December
Count Occurrences of Character in String in Python
Using count() Method Use String’s count() method to count occurrences of character in String in Python e.g. my_string.count(character). count() method returns number of occurrences of the character in String. [crayon-63bb74d38a312396128318/] We will get the following result after running the above program. [crayon-63bb74d38a314157565925/] The count() is a conventional method in Python. It holds a substring, start, […]
- 08 December
Find Character in String in Python
Using find() Method To find the character in a string in Python: Use the find() method to find the index of the first occurrence of the supplied character in the input String. Use an if statement to check if the returned index is not -1; if so, print that index; otherwise, print an error. [crayon-63bb74d38a4c8679392375/] […]
- 05 December
Remove Substring from String in Python
Use replace() Method To eliminate a substring from string in Python: Define and initiate my_string. Declare substring to remove it from my_string. Use replace() method to remove substring from string. e.g. my_string = my_string.replace(substring, "") [crayon-63bb74d38a649537212021/] The code above will print the following output on the console: [crayon-63bb74d38a64d902377711/] We tried removing the substring from my_string. […]
- 29 November
Prefix b Before String in Python
Prefix b Before String in Python Prefix b before String denotes a byte String. By putting b before String, you can convert String to bytes in Python. The upgrade from Python 2 to Python 3 was considered a major change as many new features were introduced and quite a few changes were done to the […]
- 28 November
Get String Between Two Characters in Python
Using the string-slicing technique To get String between two characters in Python: Use String’s find() method to find indices of both the characters. Use String’s slicing to get String between indices of the two characters. [crayon-63bb74d38ac8f778748764/] Output: ava2Blo In the above example, we found the position of characters J and g using the find() function […]
- 25 November
Print String Till Character in Python
A string can be termed as a collection of characters with each character occupying a particular position. Strings cannot be altered and are considered immutable in Python. Print String Till Character in Python This tutorial will demonstrate how to print string till character in Python. Using the for loop and break statement A string can […]
- 1
- 2
- 3
- …
- 6
- Nextkeyboard_arrow_right