The "Python" tuple

Source: Internet
Author: User

Python 3.6.0 (V3.6.0:41df79263a11, Dec, 07:18:10) [MSC v.1900 + bit (Intel)] on Win32
Type "Copyright", "credits" or "license ()" For more information.
>>> tuple_1 = (1, ' A ', 2, "B", 3, ' C ')
>>> Tuple_1
(1, ' A ', 2, ' B ', 3, ' C ')
>>> tuple_1 = (1, ' A ', (2, "B"), 3, ' C ')
>>> Tuple_1
(1, ' A ', (2, ' B '), 3, ' C ')
>>> Tuple_1[0]
1
>>> Tuple_1[2][0]
2
>>> tuple_1[2:]
((2, ' B '), 3, ' C ')
>>> Tuple_1[:2]
(1, ' a ')
>>> tuple_1[:]
(1, ' A ', (2, ' B '), 3, ' C ')
>>> tuple_2=tuple_1[:]
>>> tuple_2[0]=4
Traceback (most recent):
File "<pyshell#12>", line 1, in <module>
Tuple_2[0]=4
TypeError:' tuple ' object does not support item assignment
>>> tmp= (at)
>>> Type (TMP)
<class ' int ' >
>>> tmp2=1,2
>>> Type (TMP2)
<class ' tuple ' >
>>> #是不是tuple类型关键是逗号而不是小括号
>>> tmp3=[]
>>> Type (Tmp3)
<class ' list ' >
>>> #是不是list类型只要看有没有中括号
>>> tmp4= ()
>>> Type (tmp4)
<class ' tuple ' >
>>> #如果只有小括号而无逗号就是空元组
>>> tmp5= (1,)
>>> Type (TMP5)
<class ' tuple ' >
>>> TMP5
(1,)
>>> Tmp6=1,
>>> Type (TMP6)
<class ' tuple ' >
>>> 6* (6,)
(6, 6, 6, 6, 6, 6)
>>> type (6,)
<class ' int ' >
>>> tmp= (' Sweeping monk ', ' Zhang San Feng ', "Wind Qing", "Stone Break Day")
>>>tmp=tmp[:2]+ (' Guo Jing ',) +tmp[2:]
>>> tmp
(' Sweeping monk ', ' Zhang Sanfeng ', ' Guo Jing ', ' Wind Qing ', ' stone Broken Day ')
>>> #原来的tmp还存在, but no name tag affixed, will be automatically recycled by Python
>>> del tmp
>>> tmp
Traceback (most recent):
File "<pyshell#36>", line 1, in <module>
Tmp
Nameerror:name ' tmp ' is not defined
>>> #python有回收机制, no need to use Del to remove the active, no sticker will be automatically recycled

Python 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.