From 291ba8204648d16d39d374526a7566fda3f346fd Mon Sep 17 00:00:00 2001 From: leonhuang Date: Fri, 26 May 2023 14:58:20 -0500 Subject: [PATCH] Homework2 --- Leon_Submissions/Homework2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Leon_Submissions/Homework2.py b/Leon_Submissions/Homework2.py index e69de29..d49a35d 100644 --- a/Leon_Submissions/Homework2.py +++ b/Leon_Submissions/Homework2.py @@ -0,0 +1,22 @@ +# Question 7: +# 1. Strings in Python are sequences of Unicode characters, while bytes +# are sequences of raw binary data. +# 2. Strings in Python are immutable, bytes objects are mutable +# 3. Strings in Python are encoded using a specific character encoding, +# bytes objects do not have an inherent encoding and represent raw binary +# data. +import sys + +string_example = "Hello" +bytes_example = b"Hello" + +string_size = sys.getsizeof(string_example) +bytes_size = sys.getsizeof(bytes_example) + +print("Size of string:", string_size) +print("Size of bytes:", bytes_size) + +# Emojis are represented using Unicode characters, which require more +# bytes to store compared to ASCII characters. Therefore, if you have +# a string that contains emojis, its size will be larger than a string +# without emojis. \ No newline at end of file