Tuples & Dictionaries

Source: Internet
Author: User

Tuple tuples

#只能初次赋值, cannot be changed and deleted

#支持切片

>>> A
(1, 2, 3, 4, 5, 6, 7, 8, 9)
>>> a [0:6:2]
(1, 3, 5)

Type ((1,)) #tuple

Type ((1)) # int

Tuples can do formatted output

>>> print ' This number%f '% (5)
This number 5.000000
>>> print ' integer%d '% (5)
Integer 5
>>> print ' character%s '% (' abc ')
Character ABC

Dictionary

>>> zidian={' April ': ' Student ', ' Wu ': ' Teacher '}
>>>
>>> for K, V in Zidian.items ():
... print ' key:%s value:%s '% (k,v)
...
Key:april value:student
Key:wu value:teacher. Keys.values #dic [key]

>>> Zidian
{' April ': ' Student ', ' Wu ': ' Teacher '}
>>> zidian[' zhang '] = ' teacher ' #字典可赋值
>>> Zidian
{' April ': ' Student ', ' Wu ': ' Teacher ', ' Zhang ': ' Teacher '}
>>> zidian[' zhang '] = ' mysql ' #字典的值可更改
>>> Zidian
{' April ': ' Student ', ' Wu ': ' Teacher ', ' Zhang ': ' MySQL '}
>>>
>>> del zidian[' Zhang ' #字典的值可删除
>>> Zidian
{' April ': ' Student ', ' Wu ': ' Teacher '}
>>> for I inZidian.keys ():
... print I
...
April
Wu
>>> for I inzidian.values ():
... print I
...
Student
Teacher

Tuples & Dictionaries

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.