Python = = "tuples

Source: Internet
Author: User

Why should there be tuples, () can hold multiple value tuples cannot be changed more is used to query
T = (1,[1,3], ' SSS ', (UP)) #t = tuple (1,[1,3], ' SSS ', ())
Print (Type (t))

Tuples can be a key to a dictionary
d={(+): ' Zcx '}
Print (D,type (d), d[())

Index values
D = (1,2,3,4,5)
Print (d[1])

Slice
Goods = (' iphone ', ' lenove ', ' Sum ', ' vivo ')
Print (Goods[1:3])
Print ((goods))

Length
Goods = (' iphone ', ' lenove ', ' Sum ', ' vivo ')
Print (len (goods))

Contains
Goods = (' iphone ', ' lenove ', ' Sum ', ' vivo ')
Print (' iphone ' in goods)

Master
Index, Count
Goods = (' iphone ', ' lenove ', ' Sum ', ' vivo ')
Print (Goods.index (' Lenove ')) #查询索引位置
Print (Goods.count (' Lenove ')) #计数

Add: The tuple itself is immutable, but the inner child element can be changed.
t= (1,[' A ', ' B '], ' SSS ', (UP))
t = ([1],[0], ' A ')
Print (Type (t))

Do not rely on indexed values
msg_dic={
' ASD ': 1111,
' Qwe ': 1222,
' Zxc ': 33333
}
For item in Msg_dic:
Print (Item,msg_dic)

msg= ' Hello '
# msg = [+]
msg = (all in all)
For item in MSG:
Print (item)

For: Supplemental
Len () takes the index print after the value
Range: Gu Tou regardless of tail default starting from 0
For I in Range (1,10,2):
Print (i)
For I in Range (10,1,-1):
Print (i)

Python = = "tuples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.