美文网首页
Python语法笔记

Python语法笔记

作者: 1nvad3r | 来源:发表于2020-09-22 22:47 被阅读0次

    遍历数组:

    planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']
    for planet in planets:
        print(planet, end=' ') # print all on same line
    

    遍历5次:

    for i in range(5):
        print("Doing important work. i =", i)
    

    while循环:

    i = 0
    while i < 10:
        print(i, end=' ')
        i += 1
    

    list:

    squares = []
    for n in range(10):
        squares.append(n**2)
    

    字符串:

    planet = 'Pluto'
    planet[0]
    

    输出:

    "{}, you'll always be the {}th planet to me.".format(planet, position)
    

    字典:

    numbers = {'one':1, 'two':2, 'three':3}
    numbers['one']
    

    相关文章

      网友评论

          本文标题:Python语法笔记

          本文链接:https://www.haomeiwen.com/subject/cmwgyktx.html