tuple.py 856 字节
Newer Older
F
feilong 已提交
1
# -*- coding: UTF-8 -*-
F
feilong 已提交
2
# 作者:huanhuilong
F
feilong 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 标题:Python 元组
# 描述:元组的基本使用,循环打印元组成员,如果只有一个元素,应该怎么表示<br/><img src="https://img-mid.csdnimg.cn/release/static/image/mid/ask/321539019236199.jpg?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit"/>

import math


if __name__ == '__main__':
    tuple1 = ('红色',)
    for element in tuple1:
        print(element)

    tuple = ('红色', '绿色', '蓝色')
    for element in tuple:
        print(element)

    print("不带括号的也是元组:")
    r, g, b = 0.6, 0.8, 0.3
    print("普通颜色[0-1]:({}, {}, {})".format(r, g, b))

    hr, hg, hb = (math.pow(r, 3/2), math.pow(g, 4/5), math.pow(b, 3/2))
    print("使用《黑客帝国》绿色滤镜算法计算后的颜色[0-1]:({}, {}, {})".format(hr, hg, hb))