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

千鋒教育-做有情懷、有良心、有品質的職業教育機構

手機站
千鋒教育

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

千鋒教育

掃一掃進入千鋒手機站

領取全套視頻
千鋒教育

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

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

Python中如何將int轉換為string

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

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

語法-


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”整數


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)) 

輸出:



我們已經定義了將整數數據類型轉換為字符串類型的所有方法。你可以根據自己的要求使用其中的一種。

tags: python教程
聲明:本站稿件版權均屬千鋒教育所有,未經許可不得擅自轉載。
10年以上業內強師集結,手把手帶你蛻變精英
請您保持通訊暢通,專屬學習老師24小時內將與您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