购买
下载掌阅APP,畅读海量书库
立即打开
畅读海量书库
扫码下载掌阅APP

3.6 自测练习

(1)试着计算下面的运算,然后在Python中验算,看结果是否正确。

    a = 21
    b = 10
    c = 0
    c = a + b
    print ("1:c 的值为:", c)
    c = a - b
    print ("2:c 的值为:", c)
    c = a * b
    print ("3:c 的值为:", c)
    c = a / b
    print ("4:c 的值为:", c)
    c = a % b
    print ("5:c 的值为:", c)

(2)列表运算,然后在Python中验算,看结果是否正确。

    list1 = ['Python', 1997, 'hello', 2000];
    list2 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    print ("list1[0]: ", list1[0])
    print ("list1[2:4]: ", list1[0])
    print ("list2[1:4]: ", list2[1:4])
    print ("list2[2:-1]: ", list2[2:-1])

(3)元组运算(请体会与列表的不同) ,然后在Python中验算,看结果是否正确。

    tup1 = ('Python', 1997, 'hello', 2000);
    tup2 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    print ("list1[0]: ", tup1[0])
    print ("list1[2:4]: ", tup1[0])
    print ("list2[1:4]: ", tup2[1:4])
    print ("list2[2:-1]: ", tup2[2:-1])

(4)脚本练习。将上面列表运算的内容存为脚本文件,并运行。 oUnbS7FLbJ1wiMcKSmhNqqf3RW+wldeB6EIJXmbAWC091134FPj5vmfRn7UeNhnZ

点击中间区域
呼出菜单
上一章
目录
下一章
×