Homework2
This commit is contained in:
@@ -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.
|
||||
Reference in New Issue
Block a user