zoukankan      html  css  js  c++  java
  • python中二元元组的使用

    #! /usr/bin/python
    # _* _coding:UTF-8 _*_

    # the use of 2-tuple
    fruit1=("apple","banana")
    fruit2=("grape","orange")
    tuple1=(fruit1,fruit2)
    print tuple1
    print tuple1[0][1]
    print tuple1[1][1]

    print "################################################################################"

    # the package and unpackage

    tuple3=("apple","banana","grape","orange")
    a,b,c,d=tuple3
    print a,b,c,d

    print "################################################################################"

    #traverse the tuple
    tuple4=(("apple","banana"),("grape","orange"),("watermelon",),("grapefulit",))
    for i in range(len(tuple4)):
        
    print "tuple[%d]:" %i,"",
        
    for j in range(len(tuple4[i])):
            
    print tuple4[i][j],"",
        
    print

    print "################################################################################"

    # map()
    tuple5=(("apple","banana"),("grape","orange"),("watermelon",),("grapefulit",))
    k=0
    for a in map(None,tuple5) :
        
    print "tuple[%d]:" %k,"",
        
    for x in a :
            
    print x,"",
        
    print
        k+=1
        
  • 相关阅读:
    UIKit, AppKit, 以及其他API在多线程当中的使用注意事项
    BOZJ-2590 优惠券
    P3620 [APIO/CTSC 2007] 数据备份
    矩阵乘法与快速幂
    CodeForces
    AtCoder
    CodeForces
    考试成绩和学号的(结构体)排序
    CodeForces
    Atcoder Beginner Contest 092 —— C题
  • 原文地址:https://www.cnblogs.com/xpxu/p/1651308.html
Copyright © 2011-2022 走看看