搜尋此網誌

2026年4月21日星期二

Bytes Object in Python

In Python, a bytes object is an immutable sequence of integers in the range 0–255, used to represent raw binary data. It’s similar to a string, but instead of characters, it stores bytes.

Immutable: Once created, it cannot be modified (like str).

When you see a b prefix in Python output, it means the object is a bytes literal — raw binary data rather than a regular string.

UTF-8 is the most widely used character encoding today, representing every Unicode character using 1–4 bytes. It is backward-compatible with ASCII, meaning the first 128 characters (like English letters and digits) are encoded exactly the same as ASCII.

Name: Unicode Transformation Format – 8-bit.

Type: Variable-length encoding (1 to 4 bytes per character).

A bytearray in Python is very similar to a bytes object, but with one key difference: it is mutable. That means you can change its contents after creation, unlike bytes which are immutable.

In Python, string slice notation lets you extract parts of a string (substrings).

Hexadecimal (often shortened to “hex”) is a base-16 numbering system. Instead of using only digits 0–9 like decimal (base-10), it uses 16 symbols:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Compact: Easier to read than long binary strings.

Direct mapping: Each hex digit = exactly 4 bits (a “nibble”).

Common uses: Memory addresses, color codes (#FF0000 = red), encoding binary data, debugging.

# Decimal to hex print(hex(255)) # 0xff # Hex to decimal print(int("ff", 16)) # 255 # Binary ↔ Hex print(bin(0xff)) # 0b11111111 print(hex(0b1010)) # 0xa

x in 0xff

In 0xff, the 0x prefix is Python’s (and many other languages’) way of saying: “this number is written in hexadecimal (base‑16)”.

Microsoft Copilot

《燦爛千陽》最終章

約瑟終將重返迦南,何哀傷之有,

茅舍終將成為玫瑰花園,何哀傷之有,

倘有洪水將至,奪走生靈,

挪亞方舟必將在暴風眼中指引你的方向,何哀傷之有。

Why grieve? For Joseph shall return to Canaan.

Why grieve? For the hut shall become a rose garden.

Though the flood may come and sweep away all life,

the Ark of Noah shall guide you through the storm.

---哈菲茲詩句


出生地:約瑟是雅各與拉結的兒子,出生於迦南地(創世記 30:22–24)。迦南是亞伯拉罕家族的應許之地。

被賣到埃及:因兄弟嫉妒,他被賣為奴隸到埃及(創世記 37:28)。這使他離開了迦南。

在埃及崛起:約瑟憑智慧與解夢能力,成為埃及法老的宰相,掌管糧倉(創世記 41:40–41)。

饑荒與家族遷徙:迦南遭遇饑荒,雅各一家被迫前往埃及求糧。約瑟因此與家人重聚,並安排他們定居在埃及的歌珊地(創世記 47:6)。

歸返的象徵:雖然約瑟死於埃及,但他要求後代將自己的骸骨帶回迦南(創世記 50:25),象徵他最終的歸返。

Microsoft Copilot


卡勒德.胡賽尼《燦爛千陽》

李靜宜譯

Khaled Hosseini "A Thousand Splendid Suns"

controversy

diligence: careful work or great effort

facet: a particular part or aspect of something

temptation: the desire to do or have something that you know is bad or wrong

jeopardize: to risk harming or destroying something/somebody

exonerate: to officially state that somebody is not responsible for something that they have been blamed for

construe: to understand the meaning of a word, a sentence or an action in a particular way

implicit: suggested without being directly expressed

controversy: public discussion and argument about something that many people strongly disagree about, think is bad, or are shocked by

travesty: something that does not have the qualities or values that it should have, and as a result is often considered wrong or offensive

"BG computing" typically refers to background computing (processes running behind the scenes, such as data syncing, indexing, or cloud tasks).

in retrospect: thinking about a past event or situation, often with a different opinion of it from the one you had at the time

grateful: feeling or showing thanks because somebody has done something kind for you or has done as you asked

forge: to move forward in a steady but powerful way

artisan: a person who does work that needs a special skill, making things with their hands

accreditation: official approval given by an organization stating that somebody/something has achieved a required standard

notion: an idea, a belief or an understanding of something

far-fetched: ​very difficult to believe

commonplace: ​done very often, or existing in many places, and therefore not unusual


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2026年4月14日星期二

Strings in Python

In Python, you can concatenate strings using several methods: the + operator for simple joining, join() for efficiency with multiple strings, and formatted approaches like f-strings or format() for readability.

f"My number is: {5}"

F-strings (formatted string literals, introduced in Python 3.6) allow you to embed expressions directly inside a string.

Anything inside {} is evaluated as a Python expression, and its result is converted to a string.

In your case, {5} is just the literal integer 5. Python evaluates it, converts it to "5", and inserts it into the string.

literal: being the most basic meaning of a word or phrase, rather than an extended or poetic meaning

paragraph = """This is a paragraph. It can span multiple lines. No need for explicit newline characters.""" print(paragraph)

Output:

This is a paragraph. It can span multiple lines. No need for explicit newline characters.

In Python, the backslash (\) is an escape character. It signals that the next character has a special meaning or should be treated differently.

\n → newline

the text doesn't stop until it sees \'\'\'

Here, the backslashes are escaping the single quotes so Python doesn’t confuse them with the closing triple quotes. Without the backslashes, Python would think the string ended too early.

Microsoft Copilot

2026年4月13日星期一

Investigation

summon somebody (to something) | summon somebody to do something (formal) to order somebody to come to you

preamble: an introductory fact or circumstance

rack up: to collect something, such as profits or losses in a business, or points in a competition

flabbergasted: ​extremely surprised and/or shocked

"Crunch through" generally means to persistently and quickly process a large amount of work, data, or obstacles, often under pressure.

sneak: to go somewhere secretly, trying to avoid being seen

accomplice: ​a person who helps another to commit a crime or to do something wrong

far-fetched: difficult to believe and unlikely to be true

contrition: ​the feeling of being very sorry for something bad that you have done

ramification: one of a number of complicated and unexpected results that follow an action or a decision

idle: (of machines, factories, etc.) not in use

peril: serious danger

reimburse: to pay back money to somebody which they have spent or lost

grievous: ​very serious and often causing great pain or difficulty

expunge something (from something) to remove or get rid of something, such as a name, piece of information or a memory, from a book or list, or from your mind

gulp: to swallow, but without eating or drinking something, especially because of a strong emotion such as fear or surprise

succinct: expressed clearly and in a few words

intimidating: ​frightening in a way that makes a person feel less confident

explicit: (of a statement or piece of writing) clear and easy to understand, so that you have no doubt what is meant

verdict: an official judgement made in court or at an inquest

roughshod: to treat somebody badly and not worry about their feelings

regent: a member of a governing board (as of a state university)

standout: a person or thing that is very easy to notice because they are or it is better, more impressive, etc. than others in a group

critique: ​a piece of written criticism of a set of ideas, a work of art, etc.

the advent of something/somebody the coming of an important event, person, invention, etc.

conciliatory: ​having the intention or effect of making angry people calm

blot: ​a spot or dirty mark on something, made by ink (= colored liquid in a pen), etc.

hamper somebody/something to prevent somebody from easily doing or achieving something

pursuit: the act of looking for or trying to get something

admonish: to tell somebody strongly and clearly that you do not approve of something that they have done

parlance: a particular way of using words or expressing yourself, for example one used by a particular group


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2026年4月3日星期五

Booleans in Python

bool(1j)

“Is the complex number 1j considered True or False?”

- 1j is a complex number with real part 0 and imaginary part 1.

- In Python, any nonzero number (whether int, float, or complex) evaluates to True when converted to bool.

- Only 0, 0.0, or 0j (complex zero) evaluate to False.

A complex number is a number that has two parts:

z=a+bj

  • a → the real part (ordinary number line)
  • b → the imaginary part (multiplied by j in Python, or i in mathematics)

Key ideas

  • The imaginary unit j (or i in math) is defined as \sqrt{-1}.
  • Complex numbers extend the real numbers so we can solve equations like x^2+1=0, which has no real solution but has complex solutions x=\pm i.

Visual intuition

You can think of complex numbers as points on a 2D plane:

  • The horizontal axis = real part
  • The vertical axis = imaginary part
    So 3+4j is the point (3, 4).

bool('')

you’re converting an empty string ('') into a boolean value.

Rule

  • Empty sequences/collections (like '', [], {}, ()) evaluate to False.
  • Non-empty sequences/collections (like 'hello', [1], (0,)) evaluate to True.

[]List

  • A list is an ordered, mutable sequence of elements.
  • You can store mixed types (numbers, strings, other lists).
  • Lists allow indexing, slicing, and modification
my_list = [1, 2, 3, "hello"]
my_list.append(4)       # add element
print(my_list[0])       # access first element → 1

"hello" is indeed the fourth element (index 3, since Python starts counting at 0). 

{}Dictionary (or empty set, depending on usage)
  • By default, {} creates an empty dictionary.
  • A dictionary stores key-value pairs.
  • Keys must be unique and immutable (like strings, numbers, tuples).
my_dict = {"name": "Alice", "age": 25}
print(my_dict["name"])   # → Alice

()Tuple
  • A tuple is an ordered, immutable sequence.
  • Similar to a list, but you cannot change its contents after creation.
  • Often used for fixed collections of items.

my_tuple = (10, 20, 30) print(my_tuple[1]) # → 20

Data structures include list, tuple, dictionary and set.

explicit: clear and easy to understand, so that you have no doubt what is meant

a = 5

b = 5

if a - b:

    print('a and b are not equal!')

No output will be printed.

weatherIsNice = True
haveUmbrella = False

if not (haveUmbrella or weatherIsNice):
    print('Stay inside')
else:
    print('Go for a walk')

1. weatherIsNice = True
2. haveUmbrella = False
3. Inside the if condition:
-(haveUmbrella or weatherIsNice) → evaluates to (False or True)True.
-not (True)False.
4. Since the condition is False, the else block runs.

Logic explained
  • The condition says: “If you do not have an umbrella and the weather is not nice, then stay inside.”
  • In this case, the weather is nice, so you can go for a walk even without an umbrella.
weatherIsNice = True
haveUmbrella = False

if (not haveUmbrella) and (not weatherIsNice):
    print('Stay inside')
else:
    print('Go for a walk')

Logic

This condition means:

  • “Stay inside only if you don’t have an umbrella and the weather is not nice.”
  • In this case, the weather is nice, so you go for a walk.
weatherIsNice = True
haveUmbrella = False

if haveUmbrella or weatherIsNice:
    print('Go for a walk')
else:
    print('Stay inside')

Logic

This condition means:

  • “If you either have an umbrella or the weather is nice, then go for a walk.”
  • Only if both are false (no umbrella and bad weather) will it print “Stay inside.”
Microsoft Copilot

藏書票

藏書票 (Ex Libris) 被譽為「紙上寶石」或「書上蝴蝶」,是一種黏貼在書籍扉頁(書冊封面後的第一頁)上的微型版畫,用來標示書籍的所有權。

Explained mainly by Google Gemini