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 […]
- 15 April
Convert Hex to String in Python
1. Introduction The representation of data in Hexadecimal is commonly used in computer programming. It is used to represent binary data in a human-readable form, as understanding the machine language (i.e., Binary) is difficult for humans. Hexadecimal notation is used in networking protocols, e.g., IPv6 and cryptography, and widely used in graphics, e.g. to represent […]
- 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-676caf1cc254a393617745/] [crayon-676caf1cc254d357108025/] 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-676caf1cc268c543994686/] [crayon-676caf1cc2690468479619/] 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-676caf1cc2816454232048/] We will get the following result after running the above program. [crayon-676caf1cc281c812152357/] 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-676caf1cc2d5d644097727/] […]
- 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-676caf1cc31f0720333380/] The code above will print the following output on the console: [crayon-676caf1cc31f6128924536/] 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-676caf1cc3d43227164368/] Output: ava2Blo In the above example, we found the position of characters J and g using the find() function […]
- 1
- 2
- 3
- …
- 6
- Nextkeyboard_arrow_right