搜尋此網誌

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

The Birth of Microsoft

It was Paul who had the next thought: Since we were writing software for microcomputers, how about combining those two words? I agreed. We had our name: Micro-Soft.

sip: ​to drink something, taking a very small amount each time

MITS: Micro Instrumentation and Telemetry Systems

flabbergasted: extremely surprised and/or shocked

stunned: ​very surprised or shocked; showing this

A retrorocket (or retro-rocket) is a small, auxiliary rocket engine designed to produce thrust opposite to a spacecraft’s motion, enabling deceleration, braking, or maneuvering.

Altair is a global technology company providing software and AI solutions for simulation, data analytics, and high-performance computing (HPC).

A flagging economy refers to a nation's financial system that is becoming weaker, slower, or less effective, often characterized by low growth, rising unemployment, or reduced consumer spending.

the brink (of something) if you are on the brink of something, you are almost in a very new, dangerous or exciting situation

bankruptcy: IPA[ˈbæŋkrʌptsi]

prototype (for/of something) the first design of something from which other forms are copied or developed

mock-up: a model or a copy of something, often the same size as it, that is used for testing, or for showing people what the real thing will look like

cobble together: to produce something quickly and without great care or effort, so that it can be used but is not perfect

deluge: a large number of things that happen or arrive at the same time

stuff: to fill a space or container tightly with something

innards: the parts inside a machine

surpass: ​to do or be better than somebody/something

pay off: (informal) (of a plan or an action, especially one that involves risk) to be successful and bring good results

The gamble paid off.

artisanal: made in a traditional way by someone who is skilled with their hands

gravitas: the quality of being serious

behemoth: ​something that is very big and powerful, especially a company or organization

cloak: a thing that hides or covers somebody/something

ominously: ​in a way that suggests that something bad is going to happen in the future

DARPA stands for the Defense Advanced Research Projects Agency.

bean counter: a person who works with money, for example as an accountant and who wants to keep strict control of how much money a company spends

sole: only; single

lofty: very high and impressive

rudimentary: dealing with only the most basic matters or ideas


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

Google AI overview