1.type()查看變量類型
2.變量類型轉換命令
int()
:將一個數值或字符串轉換成整數,可以指定進制。float()
:將一個字符串轉換成浮點數。str()
:將指定的對象轉換成字符串形式,可以指定編碼。chr()
:將整數轉換成該編碼對應的字符串(一個字符)。ord()
:將字符串(一個字符)轉換成對應的編碼(整數)。
3.運算符
is is not |
身份運算符 |
in not in |
成員運算符 |
not or and |
邏輯運算符 |
4.換行
year = int(input('請輸入年份: '))
# 如果代碼太長寫成一行不便於閱讀 可以使用\或()折行
is_leap0 = (year % 4 == 0 and year % 100 != 0 or
year % 400 == 0)
is_leap1 = year % 4 == 0 and year % 100 != 0 or\
year % 400 == 0
print(is_leap0,is_leap1)