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
沒有留言:
發佈留言