Home
Aptitude
Categories


Home » Python » 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?
Submitted by IncludeHelp, on November 27, 2018

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"

Program:

# 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

str1 = ABCD
str2 = This is  IncludeHelp 

Other python string programs...






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.