while循环 运算符和编码

昨日回顾

1. 初识python
        python是一门弱类型的解释型高级编程语言
        解释器:
            CPython  官方提供的默认解释器. c语言实现的
            PyPy 把python程序一次性进行编译.
            IPython

    2. python的版本
        2.x
        3.x

    3. 变量
        概念: 程序运行过程中产生的中间值. 暂时存储在内存, 方便后面的程序使用它
        就是一个符号.
        x = 10
        郝建 -> 沈腾
        白云 -> 宋丹丹

        命名规范:
            1. 数字, 字母, 下划线组成
            2. 不能是数字开头, 更不能是纯数字
            3. 不能用python的关键字
            4. 不要用中文
            5. 不要太长
            6. 有意义
            7. 区分大小写
            8. 用驼峰或者下划线

        数据类型:
            1. int 整数   +-*/%  //  **
            2. str 字符串,
                把字符连城串
                字符:单一的文字符号
                '', "", ''', """
                + 拼接. 要求两端都得是字符串
                * 重复 必须乘以一个数字
            3. bool 布尔值
                True
                False
                用来判断
        用户交互
            变量 = input(提示语)

        条件判断:
            if 条件:
                if-语句块


            if 条件:
                if-语句块
            else:
                else-语句块


            if 条件1:
                if-1
            elif 条件2:
                if-2
            ......
            else:

 

今日内容

1. while循环 (难点)
        while 条件:
            循环体(break, continue)

    2. 格式化输出 
     %s 万能
     %d f"{变量}" 3. 运算符 and or not (难点) 运算顺序: ()=> not => and =>or 4. 初识编码 gbk unicode utf-8 1. ascii 8bit 1byte(字节) 256个码位 只用到了7bit, 用到了前128个 最前面的一位是0 2. 中国人自己对计算机编码进行统计. 自己设计. 对ascii进行扩展 ANSI 16bit -> 清华同方 -> gbk GBK 放的是中文编码. 16bit 2byte 兼容ascii 3. 对所有编码进行统一. unicode. 万国码. 32bit. 4byte. 够用了但是很浪费 4. utf-8 可变长度的unicode 英文: 1byte 欧洲文字: 2byte 中文: 3byte 字节(byte) 1byte = 8bit 1kb = 1024byte 1mb = 1024kb 1gb = 1024mb 1tb = 1024gb 1pb = 1024tb 预习: 字符串(记的东西) for循环

 






内容概要
1. while循环 (难点)
while 条件:
循环体(break, continue)
 1 # while True:
 2 #     content = input("请输入你要喷的内容, 输入Q退出")
 3 #     if content == "Q":
 4 #         # 退出程序 打断循环
 5 #         break # 直接跳出循环
 6 #     print("你对打野说:", content)
 7 
 8 
 9 
10 # if True:
11 #     print("娃哈哈")
12 
13 
14 # 最多喷三次
15 # count = 1
16 # while count <= 3:
17 #
18 #     # count = 1  # 次数, 死循环
19 #     content = input("请输入你要喷的内容")
20 #     print("你要对上单说:", content)
21 #
22 #     # 改变count
23 #     count = count + 1
24 
25 
26 
27 
28 
29 # continue
30 # while True:
31 #     content = input("请输入你要喷的内容, 输入Q退出")
32 #     if content == "":
33 #         continue # 停止当前本次循环. 继续执行下一次循环  不会彻底中断循环.
34 #     if content == "Q":
35 #         # 退出程序 打断循环
36 #         break # 直接跳出循环
37 #     print("你对打野说:", content)
38 
39 # 能够让循环退出: 1. break  2. 改变条件
40 
41 # continue  停止当前本次循环. 继续执行下一次循环
42 # break  彻底的干掉一个循环
43 
44 # 让程序从1数数, 数到100
45 # count = 1
46 # while count <= 100:
47 #     print(count) # 1
48 #     count = count + 1
49 
50 
51 # 计算 1-100之间所有的数的和
52 # sum = 0                 # sum: 0 + 1 + 2 + 3 + 4....99 + 100
53 # count = 1               # count: 1, 2, 3, 4, 99,100, 101
54 # while count <= 100:
55 #     sum = sum + count  # 累加运算
56 #     count = count + 1
57 # print(sum)
58 
59 # 数数. 1-100奇数
60 # count = 1
61 # while count <= 100:
62 #     print(count)
63 #     count = count + 2
64 
65 # count = 1
66 # while count <= 100:
67 #     if count % 2 == 1:
68 #         print(count)
69 #     else:
70 #         print("偶数....")
71 #     count = count + 1
View Code

 


2. 格式化输出 %s %d
f"{变量}"
 1 # name = input("请输入你的名字:")
 2 # address = input("请输入你来自哪里:")
 3 # wife = input("请输入你的老婆:")
 4 # notlike = input("请输入你不喜欢的明星:")
 5 #
 6 # print("我叫"+name+", 我来自"+address+", 我老婆是"+wife+", 我不喜欢"+notlike)
 7 # 需要掌握的内容===============
 8 # # 格式化输出
 9 # print("我叫%s, 我来自%s, 我老婆是%s, 我不喜欢%s" % (name, address, wife, notlike))
10 # # 新版本的格式化输出
11 # print(f"我叫{name}, 我来自{address}, 我老婆是{wife}, 我不喜欢{notlike}")
12 # 需要掌握的内容===============
13 #
14 # hobby = "踢球"
15 # print("我喜欢%s, 我老婆更喜欢%s" % (hobby, hobby))
16 
17 # %s 表示字符串的占位 . 全能的占位.
18 # print("周杰伦今年%s岁了" % 18)
19 # # %d 占位数字. 只能放数字
20 # print("周杰伦去年%d岁了" % 16)
21 # print("周杰伦去年%d岁了" % "16") # 报错
22 
23 # 坑, 如果这句话使用了格式化输出. % 就是占位, 如果想显示正常的%   %% 转义
24 # print("我叫%s, 我已经度过了30%的人生了" % "俞洪敏") # not enough arguments for format string
25 print("我叫%s, 我已经度过了30%%的人生了" % "俞洪敏")
View Code

 


3. 运算符 and or not (难点)
运算顺序: ()=> not => and =>or
 1 # print(3 != 3)
 2 # # print(3 <> 3) #  不等于
 3 #
 4 # print(3 >= 2)
 5 
 6 # a = 10
 7 # b = a # 把a的值  赋值给变量b
 8 # c = a
 9 # print(b)
10 # print(c)
11 
12 # a = 10
13 # b = 20
14 #
15 # a += b  # a = a + b 累加  sum = sum + count   sum += count
16 #
17 # print(a) # 30
18 # print(b) # 20
19 
20 # count = 1
21 # while count <= 100:
22 #     print(count)
23 #     # count = count + 1
24 #     count += 1
25 '''
26 a+=b  a = a + b
27 a *= b   a = a * b
28 a //= b  a = a // b
29 ...
30 
31 '''
32 
33 '''
34 and : 并且. 左右两端同时为真. 结果才能是真
35 or : 或者. 左右两端有一个是真. 结果就是真
36 not : 非. 非真既假, 非假既真 不真-> 假  不假 -> 真
37 '''
38 
39 # print(3 > 2 and 4 < 6 and 5 > 7) # False
40 # print(5 < 6 or 7 > 8 or 9 < 6 or 3 > 2)
41 # print(not 5 < 6)
42 
43 # 混合运算
44 # 运算顺序: () => not => and => or  当出现相同的运算的时候 从左往右算
45 # print(3 > 2 or 5 < 7 and 6 > 8 or 7 < 5)  # True
46 
47 # print(3 > 4 or 4 < 3 and 1 == 1)  # False
48 # print(1 < 2 and 3 < 4 or 1 > 2)  # True
49 # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1) # True
50 # print(1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8) # False
51 # print(1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
52 # print((not 2 > 1 and 3 < 4) or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6) # False
53 
54 # 当出现 x or y的时候, 判断x是否是0 如果x==0 then y 否则返回x
55 # print(1 or 2) # 1
56 # print(0 or 2) # 2
57 # print(3 or 0) # 3
58 # print(4 or 0) # 4
59 
60 # print(0 or 3 or 0 or 2 or 0 or 5 or 0 or 188)
61 # 当出现 x and y 的时候, 和or相反
62 # print(1 and 2) # 2
63 # print(0 and 3) # 0
64 # print(3 and 0) # 0
65 # print(4 and 0) # 0
66 
67 # print(9 and 3 and 4 and 1 and 4 and 8)
68 
69 # print(1 and 2 or 3) # 应付面试
70 
71 # print(1 and 2 > 4)
72 
73 # False 当成0来看
74 # print(False and 1)
75 # print(3 > 5 or 5 < 6 and 7)
76 # print(4 > 5 or 7 and 8 < 6 or 3 and 4)
77 
78 # 成员运算
79 # content = input("请输入你的评论:")
80 # if "马化腾" in content: # content中是否包含了xxx
81 #     print("你的评论不合法")
82 # else:
83 #     print("你的评论是合法的")
84 
85 # ad = input("请输入你的广告:")
86 # if "最" in ad or "第一" in ad or "全球" in ad:
87 #     print("不合法的")
88 #
89 # else:
90 #     print("合法的")
View Code

 


4. 初识编码 gbk unicode utf-8
1. ascii 8bit 1byte(字节) 256个码位 只用到了7bit, 用到了前128个 最前面的一位是0
2. 中国人自己对计算机编码进行统计. 自己设计. 对ascii进行扩展 ANSI 16bit -> 清华同方 -> gbk
      GBK 放的是中文编码. 16bit 2byte 兼容ascii
       3. 对所有编码进行统一. unicode. 万国码.  32bit. 4byte. 够用了但是很浪费

   4. utf-8 可变长度的unicode
  英文: 1byte
  欧洲文字: 2byte
  中文: 3byte
    字节(byte)
      1byte = 8bit
      1kb = 1024byte
      1mb = 1024kb
      1gb = 1024mb
      1tb = 1024gb
      1pb = 1024tb

  5.今日作业及默写
内容回顾小结
1. 循环
while 条件:
循环体(break, continue)
循环的执行过程:
执行到while的时候. 首先判断条件是否成立.如果成立. 执行循环体. 再一次判断条件.... 如果不成立. 直接跳出循环

break 跳出当前本层循环
continue 结束本次循环. 继续执行下一次循环

2. 格式化输出
%s 占位字符串(常用)
%d 占位数字
%f 占位浮点数

f"{变量}"
3. 运算符
!=
+= 累加 a += b a = a + b

and 并且, 左右两端同时为真. 结果才能是真
or 或者, 左右两端有一个是真. 结果就是真
not 非. 非真既假, 非假既真

顺序: () => not => and => or

x or y => if x == 0 then y else x
and和or相反

4. 编码
1. ascii 8bit 1byte 包含了 英文, 数字, 特殊字符, 特殊操作符
2. gbk 16bit 2byte 主要包含的: 中文, 日文, 韩文, 繁体中文
3. unicode 32bit 4byte 万国码
4. utf-8
英文: 8bit 1byte
欧洲: 16bit 2byte
中文: 24bit 3byte


转载于:https://www.cnblogs.com/liangxiaoji/p/10056519.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值