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

歡迎訪問 生活随笔!

生活随笔

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

python

Python元组练习

發布時間:2023/12/1 python 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python元组练习 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Here, we are covering following Python tuple exercises,

在這里,我們將介紹以下Python元組練習

  • Creating & printing a tuple

    創建和打印元組

  • Unpacking the tuple into strings

    將元組解包成字符串

  • Create a tuple containing the letters of a string

    創建一個包含字符串字母的元組

  • Creating a tuple containing all but the first letter of a string

    創建一個元組,其中包含字符串的除首字母外的所有字母

  • Reversing a tuple

    反轉元組

  • Consider the following program, it contains all above-mentioned exercises.

    考慮以下程序,其中包含所有上述練習。

    '''1) Creating & printing a tuple ''' cities = ("New Delhi", "Mumbai", "Indore") print("cities: ", cities) print("cities[0]: ", cities[0]) print("cities[1]: ", cities[1]) print("cities[2]: ", cities[2]) print() # prints a newline'''2) Unpacking the tuple into strings ''' str1, str2, str3 = cities print("str1: ", str1) print("str2: ", str2) print("str3: ", str3) print() # prints a newline'''3) Create a tuple containing the letters of a string ''' tpl = tuple("Hello") print("tpl: ", tpl) print() # prints a newline'''4) Creating a tuple containing all but the first letter of a string ''' # by direct string tpl1 = tuple("Hello"[1:]) print("tpl1: ", tpl1)# by string variables string = "Hello" tpl2 = tuple(string[1:]) print("tpl2: ", tpl2) print() # prints a newline'''5) Reversing a tuple ''' name = ("Shivang", "Radib", "Preeti") # using slicing technique rev_name = name[::-1] print("name: ", name) print("rev_name: ", rev_name)

    Output

    輸出量

    cities: ('New Delhi', 'Mumbai', 'Indore') cities[0]: New Delhi cities[1]: Mumbai cities[2]: Indorestr1: New Delhi str2: Mumbai str3: Indoretpl: ('H', 'e', 'l', 'l', 'o')tpl1: ('e', 'l', 'l', 'o') tpl2: ('e', 'l', 'l', 'o')name: ('Shivang', 'Radib', 'Preeti') rev_name: ('Preeti', 'Radib', 'Shivang')

    翻譯自: https://www.includehelp.com/python/python-tuple-exercises.aspx

    總結

    以上是生活随笔為你收集整理的Python元组练习的全部內容,希望文章能夠幫你解決所遇到的問題。

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