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

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonextend()

python 中的extend()函數(shù)通過(guò)將給定 iterable 的所有元素添加到列表的末尾來(lái)幫助增加列表的長(zhǎng)度。

站在用戶的角度思考問(wèn)題,與客戶深入溝通,找到慶安網(wǎng)站設(shè)計(jì)與慶安網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站建設(shè)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋慶安地區(qū)。

 **list1.extend(iterable)** #where iterable may be list, tuple, string etc. 

擴(kuò)展()參數(shù):

extend()函數(shù)接受一個(gè)參數(shù)。這個(gè)方法類似于append(),不同的是append()在列表的末尾添加了一個(gè)元素,但是在append()中我們可以添加多個(gè)元素。

參數(shù) 描述 必需/可選
可重復(fù)的 可能是列表、元組、字符串等。 需要

擴(kuò)展()返回值

這個(gè)方法不返回值。它通過(guò)添加元素來(lái)修改原始列表。

Python 中extend()方法的示例

示例 1:如何在 Python 中擴(kuò)展works()方法

 # flowers list
flowers = ['Rose', 'Lotus', 'Jasmine']

# another list of flowers
flowers1 = ['Sunflower', 'Dalia']

# appending flowers1 elements to flowers
flowers.extend(flowers1) 

輸出:

 Flowers List : ['Rose', 'Lotus', 'Jasmine','Sunflower', 'Dalia'] 

示例 2:如何將元組和集合的元素添加到列表中?

 # flowers list
flowers = ['Dalia']

# flowers tuple
flowers_tuple = ('Rose', 'Lotus')

# flowers set
flowers_set = {'Jasmine', 'Sunflower'}

# appending flowers_tuple elements to flowers
flowers.extend(flowers_tuple)

print('New flowers List:', flowers)

# appending flowers_set elements to flowers
flowers.extend(flowers_set)

print('Newer flowers List:', flowers) 

輸出:

 New flowers List: ['Dalia', 'Rose', 'Lotus']
Newer flowers List: ['Dalia', 'Rose', 'Lotus', 'Sunflower', 'Jasmine'] 

示例 3:extend()& append()在 Python 中是如何工作的?

 x1 = [1, 2]
x2 = [3, 4]
y = (5, 6)

# x1 = [1, 2, 5, 6]
x1.extend(y) 
print(x1)

# x2 = [1, 2, (5, 6)]
x2.append(y)
print(x2) 

輸出:

 [1, 2, 5, 6]
[1, 2, (5, 6)] 

新聞標(biāo)題:創(chuàng)新互聯(lián)Python教程:Pythonextend()
新聞來(lái)源:http://m.5511xx.com/article/cccpgop.html