Skip to content

Commit a684cfc

Browse files
Uploading file
Adding file into the repository
1 parent 1c1fb60 commit a684cfc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

encoding_decoding.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# Method encode() returns an encoded version of the string
3+
initial_string = 'Hello there!'
4+
encoded_string = initial_string.encode('utf-32')
5+
6+
# To choose the right Codec for needed language go to the page:
7+
# docs.python.org/3.7/library/codecs.html
8+
# Or choose 'ut-32' as standard for all languages
9+
10+
print('Encoded string of "', initial_string, '" is: ')
11+
print(encoded_string)
12+
13+
# To decode string we need to use decode function
14+
decoded_string = b'\xff\xfe\x00\x00H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00 \x00\x00\x00t\x00\x00\x00h\x00\x00\x00e\x00\x00\x00r\x00\x00\x00e\x00\x00\x00!\x00\x00\x00'.decode('utf-32')
15+
print(decoded_string)
16+
17+
# It is possile to use "Fill paragraph" option to show long string in the screen
18+
decoded_string = b'\xff\xfe\x00\x00H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00 ' \
19+
b'\x00\x00\x00t\x00\x00\x00h\x00\x00\x00e\x00\x00\x00r\x00\x00\x00e\x00\x00\x00!\x00\x00\x00' \
20+
b''.decode('utf-32')
21+
print(decoded_string)

0 commit comments

Comments
 (0)