搜尋此網誌

2026年10月13日星期二

Drawing shapes in Python

A static attribute in Python is a variable that belongs to the class itself, not to individual objects created from that class. It’s sometimes called a class attribute.

Defined inside the class, but outside any methods.

Shared by all instances of the class.

Accessed using either ClassName.attribute or object.attribute.

class Dog: # static/class attribute species = "Canis familiaris" def __init__(self, name): self.name = name # instance attribute dog1 = Dog("Rover") dog2 = Dog("Buddy") print(dog1.species) # Canis familiaris print(dog2.species) # Canis familiaris print(Dog.species) # Canis familiaris

class Shape:

    width = 5

    height = 5

    printChar = '#'

 

    def printRow(self, i):

        raise NotImplementedError("Will be implemented by children extending this class")

 

    def print(self):

        for i in range(self.height):

            self.printRow(i)

Shape class

Has static attributes: width, height, printChar.

Defines printRow() as an abstract method (raises NotImplementedError).

In Python, raise is used to trigger an exception. It tells the program: “Stop normal execution here and signal that something went wrong.”

Defines print() which loops through rows and calls printRow(i).

In your code, self.height refers to the class attribute height (which is set to 5 in Shape) but accessed through the object (self).

When you call self.height, Python first looks for an instance attribute named height.

If it doesn’t find one, it uses the class attribute height.

In your example, since you didn’t set height inside __init__, every object uses the class’s height = 5.


class Square(Shape):

    def printRow(self, i):

        print(self.printChar * self.width)


Square class

Implements printRow(i) by printing a full row of printChar repeated width times.

So Square().print() will print a solid square.


class Triangle(Shape):

    def printRow(self, i):

        # Row i has (i+1) characters

        print(self.printChar * (i + 1))


class EqilateralTriangle(Shape):

    def printRow(self, i):

        spaces = self.width - i - 1

        chars = 2 * i + 1

        print(" " * spaces + self.printChar * chars)

    #
   ###
  #####
 #######
#########

Is it a matter if i don't put "self" before "printChar"?
Yes, it does matter whether you put self. before printChar.

With self.printChar
  • Python looks for the attribute on the object (self).
  • If the object doesn’t have its own, it falls back to the class attribute (Shape.printChar).
  • This makes the code flexible: each instance can override printChar if needed.

With just printChar
  • Python will look for a local variable named printChar inside the method.
  • Since none exists, it will raise a NameError.
  • It won’t automatically use the class attribute unless you explicitly write Shape.printChar.
>>> padding = int((10 - 1)/2) >>> print (padding) 4

Microsoft Copilot

陶瓷術語十七

短流是古代陶器、青銅器常見的一種構件術語。

流:指器物上用來倒出液體的出口部分,相當於壺嘴。

短流:流部較短,通常只略微伸出器身,與「長流」相對。

Microsoft Copilot

齊家文化

齊家文化是中國西北地區早期青銅時代的重要考古文化,約公元前2400年至前1900年,分布於甘肅蘭州至青海湟水流域,被視為中國最早的青銅文化之一。 它承接馬家窯文化,並在陶器、青銅器、農業與社會制度上展現出過渡性特徵。

Microsoft Copilot

en.wikipedia.org

裝飾技法

凸弦紋是中國古代陶器、青銅器常見的一種裝飾技法。

凸弦紋:指在器物表面沿橫向或環繞器身,塑造出 凸起的弦狀線條。

「弦」在此比喻為細長的線條,凸弦紋就是將這些線條以立體方式表現。

Microsoft Copilot

陶瓷術語十六

鋬手是中國古代陶器、青銅器常見的一種器物構件術語。

鋬手:指器物在口沿或肩部兩側附加的 小耳狀把手,通常呈橫向或斜向伸出。

與「耳」或「提梁」不同,鋬手多為 短小、便於提握或繫繩 的構件。

Microsoft Copilot

2026年10月12日星期一

烙印

From a neuroplastic perspective, when you lose someone your brain is having to readjust to a completely new way of living. Over time the person you love has been ingrained into the network of neurons in your brain.

從神經可塑性的角度來看,當你失去某個人時,大腦需要重新適應一種全新的生活方式。因為隨著時間的累積,你所愛的人已經深深嵌入到大腦的神經網絡之中。

當那個人離開或過世時,原本被強化的迴路仍會被觸發,例如習慣性想起、看到熟悉物品時的情緒反應。但外在環境與互動模式已經改變,於是大腦需要重新調整,減弱某些舊有連結,建立新的連結來適應沒有對方的生活。這個過程需要時間,並伴隨悲傷、思念與行為上的改變。

agony: extreme physical or mental pain

subside: to become calmer, quieter or less intense

dump: to get rid of something you do not want, especially in a place that is not suitable

anguish: severe physical or mental pain, difficulty or unhappiness

inkling: a slight knowledge of something that is happening or about to happen

incomprehensible: impossible to understand

nonetheless: despite this fact

falling-out: a situation where people are no longer friends, because they disagree or have had an argument

taxing: needing a great amount of physical or mental effort

marine: a soldier who is trained to serve on land or at sea, especially one in the US Marine Corps or the British Royal Marines

Nicole Vignola "Rewire"

hk.dictionary.search.yahoo.com

oxfordlearnersdictionaries.com

Explained by Microsoft Copilot

2026年10月9日星期五

幸福有時

求學時間,我是一個 SEN 學生。當年根本沒有 Special Education Needs 這個 Term,那時我只是靠醫生、家人和社工渡過難關。至於是哪方面的問題,我從前很公開,但現在通常不會跟同事說。現時,我仍然要依靠藥物穩定病情。

今年,父親七十歲,母親六十六歲。每天吃的是母親煮的菜飯,住的是父親的房子。父親說過,父母緣太重,未必是一件好事。幸福的日子還能維持到何年何月,天曉得知!

自知自己的疾病有機會會遺傳到下一代,遇上心儀的異性也不會主動結交。就算對方不打算生小朋友,我也不願意拖累到別人。始終,我的病何時會復發,誰也不知道。

我今年四十歲,工作將會有轉變。雖然不是轉往另一間公司工作,但仍有很大的變數。我只可以說,今天日見夜見的同事,頗有城府,如果離開這間分店也許是一件好事。