循环,格式化,运算符

  1. 今日内容大纲

    • pycharm的安装以及简单使用

      • 辅助开发软件,代码逐行调试,设置高端,不会提示,你在书写代码时,他不提示,debug的模式,最好用的还是pycharm。

    • 格式化输出

    • while循环

    • 运算符 and or not

    • 编码的初识

  2. 昨日内容回顾

    • 编译型与解释型

      • 编译型:一次性编译成2进制,在执行

        • 优点:执行效率高

        • 缺点:不能跨平台,开发效率低

        • 代表语言:C

      • 解释型:逐行解释成二进制,在执行

        • 优点:可以跨平台,开发效率高

        • 缺点:执行效率低。

          • 代表语言:python

    • 变量:

      • 数字,字母,下划线任意组合。

      • 不能以数字开头。

      • 不能用Python的关键字:print if...

      • 不能使用中文。

      • 描述性。

      • 区分变量与数据类型的区别。

      • 1  name = 'Alex'
        2  name = '太白'
        3  print(name)
        4  name = 'wusir'
        5  print(name)

         

    • 常量

      • 一直不变的量,与变量几乎一样。

    • 注释:解释说明

    • 基础数据类型:

      • 1, 2, 3, 4000,int 数字, +-*/ % ** ....

      • 'fdsalk中国' str 字符串 + *int

      • True False bool 布尔值

    • 用户输入input

    • 1  name = input('>>>')
      2  print(type(name))

       

       

    • if

      • if 条件:

      • if else:

      • if elif elif .....

      • if elif elif ..... else

      • if 嵌套

         

3. 今日内容

  1. while 循环

    • why:大气循环, 吃饭,上课,睡觉,日复一日,歌曲列表循序环,程序中:输入用户名密码,

    • what:while 无限循环。

    • how:

      1. 基本结构:

        1  while 条件:
        2      循环体

         

      2. 初识循环

        1  while True:
        2      print('狼的诱惑')
        3      print('我们不一样')
        4      print('月亮之上')
        5      print('庐州月')
        6      print('人间')

         


             
      3. 基本原理:

         

      4. 循环如何终止?

        1. 改变条件。

          1  flag = True
          2  while flag:
          3      print('狼的诱惑')
          4      print('我们不一样')
          5      print('月亮之上')
          6      flag = False
          7      print('庐州月')
          8      print('人间')
           
           1  # 练习题: 1~ 100 所有的数字
           2  count = 1
           3  flag = True
           4  while flag:
           5      print(count)
           6      count = count + 1
           7      if count == 101:
           8          flag = False
           9          
          10  count = 1
          11  while count < 101:
          12      print(count)
          13      count = count + 1

           

          1   # 1 + 2 + 3 + ...... 100  的最终结果:
          2 3  s = 0
          4  count = 1
          5  while count < 101:
          6      s = s + count
          7      count = count + 1
          8  print(s)
          
          
        1. break

        1  # while True:
        2  #     print('狼的诱惑')
        3  #     print('我们不一样')
        4  #     print('月亮之上')
        5  #     break
        6  #     print('庐州月')
        7  #     print('人间')
        8  # print(111)

         

         

        1. 系统命令(今天不讲)

        2. continue

          1  # continue : 退出本次循环,继续下一次循环
          2  flag = True
          3  while flag:
          4      print(111)
          5      print(222)
          6      flag = False
          7      continue
          8      print(333)
          1  # while elsewhile 循环如果被break打断,则不执行else语句。
          2  count = 1
          3  while count < 5:
          4      print(count)
          5      if count == 2:
          6          break
          7      count = count + 1
          8  else:
          9      print(666)

           

           

    • where: 你需要重复之前的动作,输入用户名密码,考虑到while循环。

  2. 格式化输出

    • 当你遇到这样的需求:字符串中想让某些位置变成动态可传入的,首先要考虑到格式化输出。

  3. 运算符:算数运算符 + -,比较运算符 > ==,赋值运算符=,+=,逻辑运算符,and or, 成员运算符。

     1  i1 = 2
     2  i2 = 3
     3  print(2 ** 3)
     4  print(10 // 3)
     5  print(10 % 3)
     6  7  print(3 != 4)
     8  9  count = 1
    10  count = count + 1
    11  count += 1
    12  print(count)

     


     
     1  # and or not
     2  3  # 1 在没有()的情况下,优先级:not > and > or,同一优先级从左至右依次计算
     4  # 情况1:两边都是比较运算
     5  # print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
     6  # print(True or False)
     7  8  # 情况2:两边都是整数
     9  '''
    10  x or y , x为真,值就是x,x为假,值是y
    11  '''
    12  # print(1 or 2)
    13  # print(3 or 2)
    14  # print(4 or 2)
    15  # print(-1 or 2)
    16  # print(0 or 2)
    17 18  # print(1 and 2)
     

    数据类型之间的转换

     1 # str ---> int  : 只能是纯数字组成的字符串
     2 s1 = '00100'
     3 print(int(s1))
     4 # int ----> str
     5 i1 = 100
     6 print(str(i1),type(str(i1)))
     7 
     8 # int  ---> bool  : 非零即True ,0为False。
     9 i = 0
    10 print(bool(i))
    11 # bool ---> int
    12 print(int(True))  # 1
    13 print(int(False))  # 0

     

  4. 编码的初识重点

计算机存储文件,存储数据,以及将一些数据信息通过网络发送出去,存储发送数据什么内容?底层都是01010101.

我带这张珵穿越,1937,我俩研究电报:

真正密码本:

滴滴 走

滴滴滴 跑

第一版: 没有段位,

101

1101 晚

1 吃

11

1011101111

 

第二版:

0000101

0001101 晚

0000001 吃

0000011

0000101 0001101 0000001 0000011

密码本:01010110 二进制与 文字之间的对应关系。

最早起的密码本:

ASCII码:只包含:英文字母,数字,特殊字符。

0000 0001 : a

0000 0101 : ;

8bit == 1byte

'hello123': 8byte

 

gbk: 英文字母,数字,特殊字符和中文。国标

一个英文字母: 0000 0001 : a

一个中文 中: 0000 0001 0100 0001 : 中

 

Unicode: 万国码:把世界上所有的文字都记录到这个密码本。

起初一个字符用2个字节表示:

0000 0001 0000 0011: a

0000 0001 0100 0001 : 中

后来为了涵盖全部文字:

0000 0001 0000 0011 0000 0001 0000 0011: a

0000 0001 0100 0001 0000 0001 0000 0011 : 中

浪费空间,浪费资源。

 

Utf-8:升级:最少用8bit1个字节表示一个字符。

0000 0011: a 1字节

0000 0011 0000 0011 欧洲 2个字节

0000 0011 0000 0011 0000 0011 中: 3个字节。

重点:

'中国12he' : GBK: 8个字节

'中国12he' : UTF-8: 10个字节

 

 

 1 8bit = 1byte
 2 1024byte = 1KB
 3 1024KB = 1MB
 4 1024MB = 1GB
 5 1024GB = 1TB
 6 1024TB = 1PB
 7 1024TB = 1EB
 8 1024EB = 1ZB
 9 1024ZB = 1YB
10 1024YB = 1NB
11 1024NB = 1DB    

 

 

7.6MB ----> 7.6 * 1024 * 1024 * 8

明日内容:

1 1. 二进制与十进制之间的转换

 

  1. str bool int 转换

  2. str具体操作方法:索引切片步长,常用操作方法,

  3. for 循环

 

 

 

git :

  1. 每天上传你们的作业。 1. git add . 2. git commit -m "我上传了day02作业" 3. git push origin master

  2. 在里面讨论作业问题。

 

 

老师每天的笔记,代码,提交到码云(教学计划)

每天给你们留的作业:issues里面。

 

posted @ 2018-12-30 19:30  .如影随行  阅读(230)  评论(0编辑  收藏  举报