• 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 […]

  • Python hex to String
    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-674319384a60b403550321/] [crayon-674319384a60d102544669/] 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-674319384a70b346428720/] [crayon-674319384a70e187581195/] 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-674319384a865266624834/] We will get the following result after running the above program. [crayon-674319384a86b947760148/] 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-674319384aab7893094088/] […]

  • 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-674319384ac88824855686/] The code above will print the following output on the console: [crayon-674319384ac8b796033781/] 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-674319384ae5a150574600/] Output: ava2Blo In the above example, we found the position of characters J and g using the find() function […]