搜尋此網誌

2026年4月27日星期一

Python Quiz

In Python, int(9.9) returns 9.

Here’s why:

The int() function truncates the decimal part of a floating-point number.

It does not round — it simply drops everything after the decimal point.

So 9.9 becomes 9.

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

In Python, int and Decimal are both numeric types, but they serve very different purposes: int is for whole numbers, while Decimal is for precise decimal arithmetic, often used in finance or scientific contexts.

When you run bytes(4) in Python, it creates a bytes object of length 4, filled with zeros.

b = bytes(4)

print(b)   # b'\x00\x00\x00\x00'

bytes(n) → produces a sequence of n bytes.

Each byte is initialized to 0 (\x00 in hexadecimal).

The result is immutable, meaning you cannot change its contents after creation.

b = bytes(5)

print(b)   # b'\x00\x00\x00\x00\x00'

In Python, writing with triple quotes (''' ... ''' or """ ... """) creates a multi‑line string.

Microsoft Copilot

微距拍攝

    在微距拍攝中通常不需要使用大光圈,因為即使在中小光圈下,景深已經非常淺。在 1:1 放大倍率下,即使使用 f/8–f/11,景深也只有幾毫米。若用大光圈 (f/2.8–f/4),景深可能縮到不到 1 毫米,導致昆蟲的眼睛清晰但觸角完全模糊。大光圈下焦點範圍極窄,任何微小晃動或主體移動都會失焦。若使用小光圈 (如 f/16),光線較少,需要額外補光或使用閃燈。這也是為什麼常見的工作光圈範圍在 f/8–f/11。

    標準鏡頭即使靠近拍攝,放大倍率通常不足 1:1,景深相對較深,因此不需要像微距那樣擔心「極淺景深」。在標準鏡頭特寫中,使用大光圈 (f/1.8–f/2.8) 仍能創造淺景深效果,讓背景柔和模糊。但因為放大倍率不高,景深不會像微距那樣縮到幾乎不可用,焦點範圍仍有一定寬度。

Microsoft Copilot

2026年4月23日星期四

Practice in Python

In Python, the expression int(hexNum, 16) means “convert a hexadecimal string into a decimal integer.”

Curly brackets: dictionaries

In Python, def is the keyword used to define a function.

In Python, a for loop is used to repeat a block of code for each item in a sequence (like a list, tuple, string, or range).

for variable in sequence:

    # code block

variable → takes each value from the sequence one by one.

sequence → the collection you want to loop through.

The code block runs once for each item.

In Python, char isn’t a separate data type like in some other languages (for example, C or Java).

def check_number(n):

    if n > 0:

        return "Positive"

    elif n == 0:

        return "Zero"

    else:

        return "Negative"

print(check_number(5))   # Positive

print(check_number(0))   # Zero

print(check_number(-3))  # Negative

In Python, == is the equality operator. It’s used to check whether two values are equal.

print(2 ** 3)   # 8   (2 raised to the power of 3)
print(5 ** 2)   # 25  (5 squared)
print(10 ** 0)  # 1   (any number to the power of 0 is 1)

甚麼是風骨

……風本身是活動的,而且風碰到物,也會使物活動起來︰風吹在樹葉上,樹葉就搖動了;風吹在水上,水面就起波紋了。所以,「風」是一種動力。在具體作品中,「風」就是一種感發的力量,這是我對「風」字的比較現代的解釋……對於人和動物而言,骨是使之能夠站立起來的一種支柱。那甚麼東西使你的作品挺立起來呢?一個是要有非常真切,實在的內容;再一個就是要有很好的組織結構。所以「風骨」就是由內容思想結合了句法、章法而傳達出來的一種感發的力量。我們講詩詞的結構,說它不僅要有平仄這些外表文字的結構,還要有一個情意的結構……

節錄自葉嘉瑩《知人論詩》

2026年4月21日星期二

焦距與景深

焦距越長,景深越淺。即使在相同光圈下,長焦鏡頭的可接受清晰範圍更窄。

拍攝距離

為了保持主體大小一致,使用長焦鏡頭時需要站得更遠。這會改變背景與主體的相對比例,使背景看起來更模糊。

壓縮效果 (Compression Effect)

長焦鏡頭會「壓縮」前景與背景的距離感,背景看似更近、更大,模糊也更顯著。

模糊圈 (Circle of Confusion)

長焦鏡頭在相同構圖下,背景的模糊圈會被放大,因此失焦效果更強烈。

Microsoft Copilot

Longer focal lengths (telephoto lenses) magnify the image more than wide-angle lenses. This magnification also enlarges the blur circles of out-of-focus objects.

Aperture: Changing your f-stop adjusts the angle of the light cone. A smaller aperture (higher f-number) makes the cone narrower, reducing the size of the blur circles and increasing the depth of field.

When your subject is very close to the lens, the light rays entering the camera are highly divergent. Even a tiny movement forward or backward from the focus point causes the light cone to widen rapidly. The Circle of Confusion grows large very quickly, resulting in a shallow depth of field.

For subjects far away, the light rays are more parallel. As you move away from the perfect focus plane, the light cone widens much more slowly.

Google AI mode

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"