• while,格式化输出


    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")
                        
    

      

        

  • 相关阅读:
    Linux(实操篇)--- 实用指令-运行级别和找回root密码
    Python使用文件操作实现一个XX信息管理系统的示例
    python解释器安装教程的方法步骤
    python如何使用代码运行助手
    python 识别登录验证码图片功能的实现代码(完整代码)
    python线性插值解析
    python协程 详解
    maxcompute mapjoin
    spark split节点笔记
    安装和配置hadoop
  • 原文地址:https://www.cnblogs.com/panda-pandeyong/p/9260511.html
Copyright © 2020-2023  润新知