python基础篇之基本语法

 |   

在基本的概念和数据结构了解完后,再了解一下基本语法来将这些零件合理的组合起来,这样就可以用 Python 干一下复杂的任务了.

条件语句

  • 代码演示

    1score = 70
    2if score > 100 :
    3    print 'the score is out of range.'
    4elif score > 60 :
    5    print 'your score is from 60 to 100.'
    6elif score > 0 :
    7    print 'your score is from 0 to 60.'
    8else :
    9    print 'the score is out of range.'
    

for循环语句

  • 代码演示

    1colors = ['red','blue','green']
    2
    3for color in colors
    4    print 'color is ' + color
    
    1# print the numbers from 0 through 99
    2for i in range(100):
    3    print i
    

while循环语句

  • 代码演示

    1# list中元素a在哪个位置
    2i = 0
    3while i < len(list):
    4    if list[i] == a :
    5        print i
    6        break
    7    else :
    8        i += 1
    
技术茶话会
< 前一篇 后一篇 >