av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

Python程序:將元組轉換為字符串

創(chuàng)新互聯(lián)Python教程:

編寫一個 Python 程序,將元組轉換為字符串。我們使用 Python 字符串連接函數(shù)來連接或轉換元組項。

# Tuple To String

strTuple = ('p', 'y', 't', 'h', 'o', 'n')
print("Tuple Items = ", strTuple)

stringVal = ''.join(strTuple)
print("String from Tuple = ", stringVal)
Tuple Items =  ('p', 'y', 't', 'h', 'o', 'n')
String from Tuple =  python

使用 for 循環(huán)將元組轉換為字符串的 Python 程序

在這個 Python Tuple to String 示例中,我們使用 for 循環(huán)(對于 strTuple 中的 t)和 for 循環(huán)范圍(對于 range(len(strTuple))來迭代元組項。在循環(huán)中,我們將每個元組項連接到聲明的字符串。

# Tuple To String

strTuple = ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l')
print("Tuple Items = ", strTuple)

strVal = ''
for t in strTuple:
    strVal = strVal + t

print("String from Tuple = ", strVal)

stringVal = ''
for i in range(len(strTuple)):
    stringVal = stringVal + strTuple[i]

print("String from Tuple = ", stringVal)
Tuple Items =  ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l')
String from Tuple =  tutorial
String from Tuple =  tutorial

這個 Python 示例使用 lambda 函數(shù)將元組項轉換為字符串。

# Tuple To String

from functools import reduce

strTuple = ('t', 'u', 't', 'o', 'r', 'i', 'a', 'l', 's')
print("Tuple Items = ", strTuple)

strVal = reduce(lambda x, y: str(x) + str(y), strTuple, '')
print("String from Tuple = ", strVal)


分享名稱:Python程序:將元組轉換為字符串
網(wǎng)站地址:http://uogjgqi.cn/article/djssdjs.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流