zoukankan      html  css  js  c++  java
  • python基础二

    1、while循环

      1、while循环 无线循环

      2、while 循环的结构

          while 条件:

            循环体

      3、如何终止循环

        1、改变条件(标志位的概念)

          flag = True

          while flag:

            print('开始循环')

            flag = False #改变条件

        2、break跳出循环

          flag = True

          while flag:

            print('hello Linda')

            break #break跳出循环

        3、练习

          1、打印1--100

          方法一:

            flag = True

            i = 1

            while flag:

              print(i)

              i += 1

              if i == 101:

                flag = False 

          方法二:

            i = 1

            while i < 101

              print(i)

              i += 1

          2、计算1+2+3+、、+100

          方法一:

            flag = True

            i = 1

            count = 0

            while flag:

              count += i

              i += 1

              if i == 101:

                falg = False

            print(count)

          方法二:

            i = 1

            count = 0

            while True:

              count += i

              i += 1

              if i == 101:

                break

            print(count)

          方法三:

            i = 1

            count = 0

            while i < 101:

              count += i

              i += 1

            print(count)

        4、continue:借宿本次循环,继续下一次循环

          flag = True

          while flag:

            print(111)

            flag = False

            continue

            print(222)

          最终结果:111

        5、while else 结构:如果while循环被break打断,则else不会被执行

          1、 i = 1

            while i < 5:

              print(i)

              i += 1

            else:

              print(10)

            执行结果是:1,2,3,4,10

          2、 i = 1

            while i < 5:

              print(i)

              i += 1

              if i == 3:break

            else:

              print(6666)

            执行结果是:1,2

        6、应用场景:

          1、验证用户名密码,重新输入这个功能需要用while循环

          2、无限次的显示页面,无限次的输入

    2、格式化的输出

      1、制作一个模板,某些位置的参数是动态的,像这样,就需要格式化输出

      2、字符串的动态替换

      3、常见形式:

        name = input('请输入你的姓名:')

        age = int(input('请输入你的年龄:'))

        print('你的姓名是:%s,你的年龄是:%d' % (name,age))

        print('你的姓名是:%(name)s,你的年龄是%(age)d' % {'name':name,'age':age})

        注意:在格式化输出中,只想单纯的表示一个%时,应该用%% 表示

            msg = '我叫%s,今年%d,我的学习进度1%%' % ('张三',28)

            print(msg)

    3、运算符

      1、== 比较两边的值是否相等

      2、= 赋值运算

      3、!= 不等于

      4、+= -= *= /= **= //= %= 等等

      5、逻辑运算符 and or not

      6、优先级 ()>>not>and>or

      7、前后条件为比较运算    

        print(1 < 2 or 3 > 1)
        print(1 < 2 and 3 > 4)
        print(1 < 2 and 3 > 4 or 8 < 6 and 9 > 5 or 7 > 2)
        print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8)
        print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6)

        执行结果为:True、False、True、False、False

      8、前后两边的条件为数值

        x or y,if x isTrue,return x

        x is False,return y

          print(1 or 2)
          print(1 and 2)
          print(5 or 2)
          print(5 and 2)
          print(0 or 2)
          print(-1 or 2)

          执行结果为:1、2、5、2、2、-1

      9、补充类型转换

        1、int转bool  0为False,非0都是True

        2、bool转int  True 1 False 0

    4、编码初识 

      ASCII: 最初版本的密码本:所有的英文字母,数字,特殊字符。
      最初:
      一个字符 000 0001
      后来优化
      A: 01000001 8位 == 1个字节
      a: 01100001
      c: 01100011
      对于ASCII码来说:
      'hello laddy' 11个字符,11个字节。

      unicode:万国码,将所有国家的语言文字都写入这个密码本。
      起初:1个字符 16位 2个字节表示。
      A: 01000001 01000001
      b: 01000001 01100001
      中:01000001 01100101
      改版:1个字符 32位 4个字节表示。
      A: 01000001 01000001 01000001 01000001
      b: 01000001 01100001 01000001 01000001
      中:01000001 01100101 01000001 01000001
      浪费资源,占空间。

      utf-8: 最少用8位表示一个字符。
      A: 01000001 一个字节
      欧洲文字: 01000001 01100001 两个字节
      中:01000001 01100101 01000001 三个字节
      'old学校':9个字节

      gbk:国标,只包含 中文,英文(英文字母,数字,特殊字符)
      A: 01000001 一个字节
      中:01000001 01100101 两个字节


      8 bit == 1bytes
      1024bytes == 1kb
      1024kb == 1MB
      1024MB == 1GB
      1024GB == 1TB
      1024TB == 1PB

        

        

               

  • 相关阅读:
    Ruby的一些基本知识
    Seleniumwebdriver系列教程(七)————如何处理alert和confirm
    Seleniumwebdriver系列教程(八)————如何操作select下拉框
    Ruby 控制结构
    Seleniumwebdriver系列教程(十)————使用jquery辅助进行测试
    Ruby是一门面向对象语言
    Seleniumwebdriver系列教程(九)————如何智能的等待页面加载完成
    Ruby 正则表达式
    执行ajax成功后进行页面的刷新
    Nacos介绍与安装启动
  • 原文地址:https://www.cnblogs.com/echo-up/p/9416419.html
Copyright © 2011-2022 走看看