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字节)

  • 相关阅读:
    只要三步,使用html5+js实现像素风头像生成器
    按Ctrl+Enter发送的实现
    “放到桌面”的Servlet实现
    从tom大叔那想着拿书的,呵呵。
    也写dateUtil.js
    智习室
    零基础爬虫课,不会编程也能做爬虫
    1小时教你学会如何采集微博数据:0基础小白也能轻松学会!
    TransactionScope 分布式事务配置
    centos7创建共享文件夹
  • 原文地址:https://www.cnblogs.com/bk9527/p/9811678.html
Copyright © 2011-2022 走看看