×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python | Assign Hexadecimal values in the string and print it in the string format

Printing Hexadecimal values as the python string: Here, we are going to learn how to assign hexadecimal values to the string and how to print the string against the assigned hexadecimal values? By IncludeHelp Last updated : February 13, 2024

To assign a hexadecimal value in the string so that it can be printed as a string, we use \x that is known as Escape sequence”, it represents that given value is the hexadecimal value.

Example

Input:
str = "\x41\x42\x43\x44"
Output:
str = "ABCD"

Input:
str = "This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"
Output:
str = "This is  IncludeHelp"

Python program to assign hexadecimal to string

# python program to assign hexadecimal values
# to the string

# declare and assign strings
str1 = "\x41\x42\x43\x44"
str2 = "This is  \x49\x6E\x63\x6C\x75\x64\x65\x48\x65\x6C\x70"

# printing strings
print("str1 =", str1)
print("str2 =", str2)

Output

The output of the above program is:

str1 = ABCD
str2 = This is  IncludeHelp 

Python String Programs »

To understand the above program, you should have the basic knowledge of the following Python topics:

Related Programs

Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.