《本办法学python——习题37》

—————————————————————————————————————————————————————————————————————————————————————

便签堆了一桌,写一写理一理

—————————————————————————————————————————————————————————————————————————————————————

一. 关键字

1.判断、循环

  ——(for,while,if,elif,else,in,and,or,not)

  1.1. 判断

    and,or,not 用于判断条件的成立与否。

  1.2. 循环

    for循环—— 

        for A in B/ for A range(c, d, f):

          content

          return X, Y, Z..

    while循环——

        while True:

          content

          return X,Y,Z..

   1.3.补充——循环  

         break.(终止循环)

                

 1 def test(a, b):
 2     a = int(raw_input("> "))
 3     b = int(raw_input(">> "))
 4     
 5     while True:
 6         if a >= b:
 7             print a 
 8             break
 9         else:
10             a += 1
11     
12     print "Test is over."
13     
14     
15 num1 = 0
16 num2 = 0            
17 test(num1, num2)

 

2.函数和模块

  —— def, return,lamda, global; from, import, as

 

3.几个其他关键字

  with

  

with open("test.txt") as file:  
    print file.read()  

  

  assert:判断能否插入,如有无字符串

  用法: assert list is None

   》》Assertion Error

  

  del:删除list中的字符串

  用法: list.del[x,y] # x,y为基数

 

  exec:

  

a = "print\" this is a test.\""
exec a

 

4.其他不熟悉的关键字

  is(用于判断)

  异常:try、finally、except、raise

  函数:lambda、pass、class、

  其他:yield

posted on 2016-08-11 19:04  公子不吃梨  阅读(307)  评论(0编辑  收藏  举报