(Self-hing Artificial intelligence) Pythony tuple

Source: Internet
Author: User

How to set up a tuple:

Tuples are wrapped in parentheses, and the elements in parentheses are separated by commas to indicate that this is a tuple.

A tuple differs from a list in that the elements inside a tuple cannot be modified.

A= (a)

Tuples Common operations:

Tuple function: Take a sequence as an argument and convert it to a tuple

a=[1,2,3]# list c=tuple (a)print(c)#( a) result

Access tuples: You can use the subscript index to access the values in the tuple

A= (1,2,3,4,5,6)print(a[4])# results

Connecting tuples: element values in tuples are not allowed to be modified, but they can be combined to join groups of tuples

A= ('md','FK') b= (up to) C=a+b  Print(c) ('md','FK', up)  # Results

Delete tuples: Values in tuples do not allow individual deletions, but you can use the DEL statement to delete an entire tuple

A= (a)del  aprint(a)# result Error

Tuple intercept: Use an index to intercept values in a segment of a tuple

A= (1,2,3,4,5,6)print(A[2:5])# intercept starting at index 2 (including values on index 2) to end of index 5 (does not intercept values on index 5)(3, 4, 5) # Results

(Self-hing Artificial intelligence) Pythony tuple

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.