diff --git a/max submission/5_26_HW.py b/max submission/5_26_HW.py new file mode 100644 index 0000000..28aaeea --- /dev/null +++ b/max submission/5_26_HW.py @@ -0,0 +1,20 @@ +# Question7: +# Difference: +# 1. Byte objects are sequence of Bytes, whereas Strings are sequence of characters. +# 2. Byte objects are in machine readable form internally; Strings are only in human readable form. +# 3. strings (str) support various character encodings, such as UTF-8, ASCII, and more. Bytes (bytes), on the other hand, represent raw binary data and can hold any byte values. +## Emojis can affect the size difference. +import sys +string_size = sys.getsizeof("Hello") +bytes_size = sys.getsizeof(b"Hello") +emoji_size = sys.getsizeof("😀") +print(f"String size: {string_size} bytes") +print(f"Bytes size: {bytes_size} bytes") +print(f"emoji size: {emoji_size} bytes") + +# python routine: +def print_string_as_numbers(string): + for char in string: + print(ord(char)) +input_string = "Hello, world!" +print_string_as_numbers(input_string) \ No newline at end of file