新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:python的str函數(shù)怎么用
str函數(shù)是Python的內(nèi)置函數(shù),其語(yǔ)法格式為

str(object)
返回值:
返回object的字符串形式
使用示例
1. 無(wú)參調(diào)用
當(dāng)str()函數(shù)的參數(shù)都省略時(shí),函數(shù)返回空字符串。這種情況常用來(lái)創(chuàng)建空字符串或者初始化字符串變量。
>>> str() ''
2. 不省略參數(shù)
str函數(shù)將整數(shù)、浮點(diǎn)數(shù)、列表、元組、字典和集合轉(zhuǎn)換為字符串類型
>>> str(-23) #整數(shù)轉(zhuǎn)換為字符串 '-23' >>> str(1.3e2) #浮點(diǎn)數(shù)轉(zhuǎn)換為字符串 '130.0' >>> a_list = [12, '-23.1', 'Python'] >>> str(a_list) #列表轉(zhuǎn)換為字符串 "[12, '-23.1', 'Python']" >>> str(a_list)[0] '['
python學(xué)習(xí)網(wǎng),大量的免費(fèi)python學(xué)習(xí)視頻,歡迎在線學(xué)習(xí)!
分享文章:創(chuàng)新互聯(lián)Python教程:python的str函數(shù)怎么用
當(dāng)前URL:http://fisionsoft.com.cn/article/coocecc.html


咨詢
建站咨詢
