pythonday2

1.

 while循环:

  while 条件:

    代码块(循环体)

  

num=1
while num<=5:
    print(num)
    num+=1

  break:结束循环;停止当前本层循环

  continue:结束本次循环,继续下次循环

2.

 格式化输出:

  符号:+  连接左右字符,

    %s 表示字符串占位符,可以放置任何内容

    %d 数字占位符,只能放置数字

  若字符串中有占位符,后面所有%均是占位符,需要转义为:%%

  

name=input("name")
age=input("age")
job=input("job")
info="""
        name:%s
        age:%s
        job:%s
""" % (name,age,job)
print(info)

3.

 运算符

  1>+ ,- ,* ,% ,**(幂) ,//(取整) ,

  2>比较:  ==  , !=(表示判断)  , <>(不等于)  , >=  ,  >=

  3>赋值:  =  ,  +=   ,  *=   ,  /=

  4>逻辑运算:  

    and 且   表示左右俩端均为真结果为真

    or   或    表示左右俩端至少有一个为真结果为真

    not  非   表示非真既假,非假既真

             优先级:  not>and>or

    判断下列结果:

      3 > 1 and 3................................................3

      3 and 2 > 1.................................................True

      3 >1 and 2 or 2 <3 and 4 or 3 > 2...............2

    

4.

   (补充)else

  

while True:
        a=input("请输入:")
        if a=="panda":
            print("nice")
        else:
            print("bad")
                    

  

    

猜你喜欢

转载自www.cnblogs.com/panda-pandeyong/p/9260511.html