日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python学习笔记一:数据类型转换

發(fā)布時間:2024/9/30 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python学习笔记一:数据类型转换 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

http://www.cnblogs.com/dabiao/archive/2010/03/07/1680096.html


我又土了,,,都是用string.atoi之類的實(shí)現(xiàn)的


aa = int("124") ? ?#Correct


? print "aa = ", aa ?#result=124
? bb = int(123.45) #correct
? print "bb = ", bb #result=123
? cc = int("-123.45") ?#Error,Can't Convert to int
? print "cc = ",cc
?dd = int("34a") ? ?#Error,Can't Convert to int
?print "dd = ",dd
?ee = int("12.3") #Error,Can't Convert to int
?print ee

print int('f') #error

print int('f',16) 15#用16進(jìn)制的標(biāo)準(zhǔn)解析


aa = float("124") ? ? #Correct
?print "aa = ", aa ? ? #result = 124.0?
?bb = float("123.45") ?#Correct
?print "bb = ", bb ? ? #result = 123.45
?cc = float(-123.6) ? ?#Correct
?print "cc = ",cc ? ? ?#result = -123.6
?dd = float("-123.34") #Correct
?print "dd = ",dd ? ? ?#result = -123.34
?ee = float('123v') ? ?#Error,Can't Convert to float
?print ee


aa = str(123.4) ? ? #Correct
?print aa ? ? ? ? ? ?#result = '123.4'
?bb = str(-124.a) ? ?#SyntaxError: invalid syntax
?print bb
?cc = str("-123.45") #correct
?print cc ? ? ? ? ? ?#result = '-123.45'
?dd = str('ddd') ? ? #correct
?print dd ? ? ? ? ? ?#result = ddd
?ee = str(-124.3) ? ?#correct
?print ee ? ? ? ? ? ?#result = -124.3


int(x [,base ]) ? ? ? ? 將x轉(zhuǎn)換為一個整數(shù) ?
long(x [,base ]) ? ? ? ?將x轉(zhuǎn)換為一個長整數(shù) ?
float(x ) ? ? ? ? ? ? ? 將x轉(zhuǎn)換到一個浮點(diǎn)數(shù) ?
complex(real [,imag ]) ?創(chuàng)建一個復(fù)數(shù) ?
str(x ) ? ? ? ? ? ? ? ? 將對象 x 轉(zhuǎn)換為字符串 ?
repr(x ) ? ? ? ? ? ? ? ?將對象 x 轉(zhuǎn)換為表達(dá)式字符串 ?
eval(str ) ? ? ? ? ? ? ?用來計(jì)算在字符串中的有效Python表達(dá)式,并返回一個對象 ?
tuple(s ) ? ? ? ? ? ? ? 將序列 s 轉(zhuǎn)換為一個元組 ?
list(s ) ? ? ? ? ? ? ? ?將序列 s 轉(zhuǎn)換為一個列表 ?
chr(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個字符 ? range [0..255]
unichr(x ) ? ? ? ? ? ? ?將一個整數(shù)轉(zhuǎn)換為Unicode字符 ?unichr(0x6211) ‘我’的unicode是 6211
ord(x ) ? ? ? ? ? ? ? ? 將一個字符轉(zhuǎn)換為它的整數(shù)值 ?
hex(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個十六進(jìn)制字符串 ?
oct(x ) ? ? ? ? ? ? ? ? 將一個整數(shù)轉(zhuǎn)換為一個八進(jìn)制字符串 ?


與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的Python学习笔记一:数据类型转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。