iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 4
0
自我挑戰組

自我學習python系列 第 4

Python的數值資料型態!

在學校想半天突然想到,python的數值資料型態是否跟我學過的其他語言一樣呢?
於是找了找接著聽我娓娓道來!~~

python的數值資料型態分為兩種

第一種:數值:int,float,bool~
int 也是大家最熟的整數
float 就是浮點數(有小數點的那種)
bool 就是布林值true or false

以整數為例python有type功能可以知道資料型態的模式像這樣

i = 5
print(i)
print(type(i))

https://ithelp.ithome.com.tw/upload/images/20190918/20121024SR89Va9QNy.png

就可以知道5是int了!

第二種:字串型態:str,chr
str 是字串需要用''或著""包起來的文字,是很多字元組成
chr 是字元 就是組成字串需要的元素

以字串為例

name = "Tony"
print(name)
print(type(name))

https://ithelp.ithome.com.tw/upload/images/20190918/20121024LMyTzEbXSB.png

而數值之間是可以轉換的
我們假設把float轉成int!

floatex1 = 38.0
intex1 = int(floatex1)
print(floatex1)
print(intex1)
print(type(floatex1))
print(type(intex1))

https://ithelp.ithome.com.tw/upload/images/20190918/20121024vZErFUpwDn.png


上一篇
Hello World!
下一篇
睡過頭的第五天~標記與變數
系列文
自我學習python30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言