国产一区二区精品-国产一区二区精品久-国产一区二区精品久久-国产一区二区精品久久91-免费毛片播放-免费毛片基地

千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構

手機站
千鋒教育

千鋒學習站 | 隨時隨地免費學

千鋒教育

掃一掃進入千鋒手機站

領取全套視頻
千鋒教育

關注千鋒學習站小程序
隨時隨地免費學習課程

當前位置:首頁  >  技術干貨  > Python中如何將int轉(zhuǎn)換為string

Python中如何將int轉(zhuǎn)換為string

來源:千鋒教育
發(fā)布人:xqq
時間: 2023-07-21 17:01:39 1689930099

我們可以使用 Python 內(nèi)置的 str() 函數(shù)來轉(zhuǎn)換整數(shù)數(shù)據(jù)類型。此函數(shù)將任何數(shù)據(jù)類型作為參數(shù),并將其轉(zhuǎn)換為字符串。但是我們也可以使用“%s”文本并使用。format()函數(shù)。下面是 str() 函數(shù)的語法。

語法-


str(integer_Value)

讓我們理解下面的例子。

示例- 1 使用 str()功能


n = 25
# check  and print type of num variable
print(type(n))
print(n)

# convert the num into string
con_num = str(n)

# check  and print type converted_num variable
print(type(con_num))
print(con_num)

輸出:


25

25

示例- 2 使用“%s”整數(shù)


n = 10

# check and print type of n variable
print(type(n))

# convert the num into a string and print
con_n = "% s" % n
print(type(con_n))

輸出:



示例- 3:使用。格式()功能


n = 10

# check  and print type of num variable
print(type(n))

# convert the num into string and print
con_n = "{}".format(n)
print(type(con_n))

輸出:



示例- 4:使用 f 弦


n = 10

# check  and print type of num variable
print(type(n))

# convert the num into string
conv_n = f'{n}'

# print type of converted_num
print(type(conv_n)) 

輸出:



我們已經(jīng)定義了將整數(shù)數(shù)據(jù)類型轉(zhuǎn)換為字符串類型的所有方法。你可以根據(jù)自己的要求使用其中的一種。

tags: python教程
聲明:本站稿件版權均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
請您保持通訊暢通,專屬學習老師24小時內(nèi)將與您1V1溝通
免費領取
今日已有369人領取成功
劉同學 138****2860 剛剛成功領取
王同學 131****2015 剛剛成功領取
張同學 133****4652 剛剛成功領取
李同學 135****8607 剛剛成功領取
楊同學 132****5667 剛剛成功領取
岳同學 134****6652 剛剛成功領取
梁同學 157****2950 剛剛成功領取
劉同學 189****1015 剛剛成功領取
張同學 155****4678 剛剛成功領取
鄒同學 139****2907 剛剛成功領取
董同學 138****2867 剛剛成功領取
周同學 136****3602 剛剛成功領取
相關推薦HOT