zoukankan      html  css  js  c++  java
  • 列表和元组操作.py

    magicians = ['alice','david','carolina']        #for循环操作
    for magician in magicians:                      #不要遗漏冒号
        print(magician)
        print( magician.title()+', that was a great trick')
        print("I can't wait to see your next trick," + magician.title()+".
    ")
        
    print('Thank you,everyone.That was a great magic show!')
    
    
    for value in range(1,5):                        #使用range 函数
        print(value)
    
    numbers = list(range(1,6))
    print(numbers)
    
    even_numbers = list(range(2,11,2))
    print(even_numbers)
    
    squares =[]
    for value in range(1,11):
        square = value**2
        squares.append(square)
    print(squares)
    
    squares = [value**2 for value in range(1,11)]
    print(squares)
    
    digits = [1,2,3,4,5,6,7,8,9,0]                  #简单统计计算
    print(min(digits))
    print(max(digits))
    print(sum(digits))
    
    
    players = ['charles','martina','michael','florence','eli']# 切片
    print(players[0:3])
    print(players[1:4])
    print(players[:3])
    print(players[2:])
    print(players[-3:])
    
    players = ['charles','martina','michael','florence','eli']
    
    print("Here are the first three players on my team:")   #for循环遍历切片
    for player in players[:3]:
        print(player.title())
    
    my_foods = ['pizza','falafel','carrot cake',]
    friend_foods = my_foods[:]
    
    
    my_foods.append('cannali')
    friend_foods.append('ice creame')
    
    print('My favourate foods are:')
    print(my_foods)
    
    
    print("
    My friend's favourate foods are:")
    print(friend_foods)
    
    print("The first three iteams in the list are:")
    print(my_foods[0:4])
    
    
    
    dimensions= (200,5)                         #遍历元组所有值
    print(dimensions[0])
    print(dimensions[1])
    for dimension in dimensions:
        print(dimension)
    
    
    dimension = (200,50)                        #修改元组变量
    print("Original dimensions:")
    for dimension in dimensions:
        print(dimension)
    
    dimensions = (400,10)
    print("
    Modified dimensions:")
    for dimension in dimensions:
        print(dimension)
  • 相关阅读:
    VC得到当前目录与得到应用程序目录的一个应用
    VC回车键的使用
    VC保存和显示数据库图像(BMP)
    windows2003 oracle817过防火墙方法
    美化VC界面(用户登录界面)
    系统要关闭,可我程序还有事要处理?
    VC保存和显示数据库图像(JPG、JPEG)
    VC应用程序快捷方式带参数
    O(n)回文子串算法
    [转]经典字符串哈希算法
  • 原文地址:https://www.cnblogs.com/dws-love-jfl-1314/p/5865759.html
Copyright © 2011-2022 走看看