A tuple in Python

Source: Internet
Author: User
# tuple# tuple and list are very similar, but the tuple cannot be modified once initialized classmates = (' Michael ', ' Bob ', ' Tracy ') print ("Classmates (tuple)", Classmates) # defines an empty Tuplet = () print ("t (empty tuple)", T) # defines a tuple with only 1 elements, plus a comma t = (1,) # A tuple is also added with a comma when displaying a tuple of only one element. So as not to misunderstand the bracket print in the mathematical sense ("t (tuple only), T) # When defining a tuple with only one element, if you do not add a comma, the system will assume that the parentheses in the mathematical formula T = (1) print (" t (not a tuple,is a brackets) ", T) # a" mutable "tuple# a tuple starts to point to the list and does not change to another list, so the so-called" invariant "of a tuple is to say that each element of a tuple, pointing to never changing # that points to ' a ', cannot be changed to point to ' B ', Pointing to a list cannot be changed to point to other objects, but the list itself is mutable! t = (' A ', ' B ', [' A ', ' B ']) t[2][0] = ' X ' t[2][1] = ' Y ' Print ("t (change list of the tuple)", T)


A tuple in Python

Related Article

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.