日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
Python程序:將元組轉(zhuǎn)換為字符串

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

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

# 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)將元組轉(zhuǎn)換為字符串的 Python 程序

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

# 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

這個(gè) Python 示例使用 lambda 函數(shù)將元組項(xiàng)轉(zhuǎn)換為字符串。

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


本文標(biāo)題:Python程序:將元組轉(zhuǎn)換為字符串
轉(zhuǎn)載源于:http://www.5511xx.com/article/djssdjs.html