zoukankan      html  css  js  c++  java
  • while循环,运算符,格式化输出

    1、while循环

      1.1  结构:while +条件判断:

              while 循环体

           else:

              条件不成立时语句块

           while...else...是一个循环整体,当循环条件成立时执行while循环体内容;循环条件不成立时跳出循环执行else内容。

           

      1.2 注意: while +条件判断:

                  ( while 循环体)

              if +条件判断:

                break

           else:

                   条件不成立时语句块

           print ( "ok" ) 

           如果循环体里面有break时,程序直接跳出while...else...大循环整体,不会执行else语句,而是输出 "ok" 。

    2、格式化输出

      方式一:通过"%s" 占位符实现格式化。

          name = input ( "姓名:" )

          age = input ( "年龄:" ) 

          print ("大家好,我是%s,今年%s岁." %( name, age ))

      方式二 : 通过  f" {变量} "

          name = input("姓名: ")

          print(f" {name} ")

      方式三:通过format() 方法实现格式化。

          Name = input("姓名:")

          age = input ("年龄:")

          print (" 大家好,我是{name},今年{age}岁。".format(name = Name, age = Age))

    3、基本运算符

      逻辑运算符   (),not,and,or

      运算顺序:() > not > and > or

       例:print ( not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 )   ----> False

        print ( 3<2 and 5 )    ----> False

        print (True and 5 )    ----> 5

        print ( 0 or 5 )    ---->  5

        print ( 0 and 5)   ---->  0

        print ( False and 0  )     ---->  False

           print ( False or 0 )   ---->  0

        print ( 0 and False )    ---->   0

        总结:0 和 False 都可以当成是假命题,而且都有意义,按照or 、 and来判断

    4、编码的发展史

      ascii                     ---->                          GBK                            ---->                                Unicode  ---->                              UTF-8 (可伸缩的unicode,节省空间)

    ( 占8 bit,一个字节 )                     (占16 bit,2个字节)                                      (占32 bit,4个字节)    (英文占8bit,1字节;欧洲文字占16 bit,2字节;中文占24 bit,3字节)

  • 相关阅读:
    return和yield的区别
    基本装饰器
    javascript实例:两种方式实现tab栏选项卡
    javascript实例:路由的跳转
    javascript实例:点亮灯泡
    标签页QTabWidget
    主窗口QMainWindow和启动画面
    各种对话框
    列表视图QlistView
    拆分窗口QSplitter
  • 原文地址:https://www.cnblogs.com/bk9527/p/9811678.html
Copyright © 2011-2022 走看看