開始使用免費開始

與其他資料類型的運算

Python 中的變數有不同的資料類型。你可以使用 type() 查看變數的類型。比如,要查看 a 的類型,可執行:type(a)

不同資料類型在 Python 中的行為也不同。比如,將兩個字串相加,與將兩個整數或兩個布林值相加,它們的表現是不一樣的。

現在,你可以動手試一試。

本練習屬於課程

Python 入門

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

savings = 100
new_savings = 40

# Calculate total_savings using savings and new_savings
____
print(total_savings)

# Print the type of total_savings
print(____)
編輯並執行程式碼