日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

适用于各种列表操作的Python程序

發布時間:2025/3/11 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 适用于各种列表操作的Python程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Here, we are implementing a python program for various list operations, following operations are being performed in the list,

在這里,我們正在為各種列表操作實現python程序,正在列表中執行以下操作,

  • Declaring an integer list

    聲明一個整數列表

  • Printing the complete list

    打印完整列表

  • Printing the first element of the list

    打印列表的第一個元素

  • Printing ith element of the list

    打印列表的第i個元素

  • Printing elements within the given indexes

    在給定索引中打印元素

  • Printing a specific element using negative indexing

    使用負索引打印特定元素

  • Appending an element to the list

    將元素追加到列表

  • Finding the index of a specific element in the list

    在列表中查找特定元素的索引

  • Sorting the list elements

    排序列表元素

  • Popping an element from the list

    從列表中彈出一個元素

  • Removing specified element from the list

    從列表中刪除指定的元素

  • Inserting an element at specified index

    在指定索引處插入元素

  • Extending the list i.e. insert set of element (list) in the list

    擴展列表,即在列表中插入一組元素(列表)

  • Reversing list elements

    反轉列表元素

  • 用于各種列表操作的Python代碼 (Python code for various list operation)

    # Python code for various list operation# declaring a list of integers iList = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]# List slicing operations # printing the complete list print('iList: ',iList) # printing first element print('first element: ',iList[0]) # printing fourth element print('fourth element: ',iList[3]) # printing list elements from 0th index to 4th index print('iList elements from 0 to 4 index:',iList[0: 5]) # printing list -7th or 3rd element from the list print('3rd or -7th element:',iList[-7]) # appending an element to the list iList.append(111) print('iList after append():',iList)# finding index of a specified element print('index of \'80\': ',iList.index(80))# sorting the elements of iLIst iList.sort() print('after sorting: ', iList);# popping an element print('Popped elements is: ',iList.pop()) print('after pop(): ', iList);# removing specified element iList.remove(80) print('after removing \'80\': ',iList)# inserting an element at specified index # inserting 100 at 2nd index iList.insert(2, 100) print('after insert: ', iList)# counting occurances of a specified element print('number of occurences of \'100\': ', iList.count(100))# extending elements i.e. inserting a list to the list iList.extend([11, 22, 33]) print('after extending:', iList)#reversing the list iList.reverse() print('after reversing:', iList)

    Output

    輸出量

    iList: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] first element: 10 fourth element: 40 iList elements from 0 to 4 index: [10, 20, 30, 40, 50] 3rd or -7th element: 40 iList after append(): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111] index of '80': 7 after sorting: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 111] Popped elements is: 111 after pop(): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] after removing '80': [10, 20, 30, 40, 50, 60, 70, 90, 100] after insert: [10, 20, 100, 30, 40, 50, 60, 70, 90, 100] number of occurences of '100': 2 after extending: [10, 20, 100, 30, 40, 50, 60, 70, 90, 100, 11, 22, 33] after reversing: [33, 22, 11, 100, 90, 70, 60, 50, 40, 30, 100, 20, 10]

    翻譯自: https://www.includehelp.com/python/program-for-various-list-operations.aspx

    總結

    以上是生活随笔為你收集整理的适用于各种列表操作的Python程序的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。