Day 02 Pycharm安装 ;格式化输出 ;while循环 ;运算符 and or not ;编码的初识

1.今日内容大纲

  • Pycharm安装以及简单使用
    • 辅助开发软件,代码逐行调试,设置高端,不会提示,书写代码时不提示错误。debug的模式最好用的还是Pycharm
  • 格式化输出
  • while循环
  • 运算符 and or not
  • 编码的初识

2.昨日内容回顾

  • 编译型与解释性
    • 编译型:一次性编译成2进制,再执行
      • 优点:执行效率高
      • 缺点:不能跨平台,开发效率低
      • 代表语言:C
    • 解释型:逐行编译成2进制,再执行
      • 优点:可以跨平台,开发效率高
      • 缺点:执行效率低
      • 代表语言:Python
  • 变量:
    • 如何设置一个变量?
      • 数字字母下划线任意组合
      • 不能用以数字开头
      • 不能用python的关键字:print if
      • 不能使用中文
      • 要具有描述性
      • 区分变量与数据类型的区别。
name = alex
name = '太白'
print(name)
name = 'wusir'
print(name)
  • 常量

    • 一直不变的量
  • 注释:解释说明

    • ‘’‘ ’‘’
    • “”“ ”“”“
  • 基础数据类型

    • 1,2,3,4000 , 数字,int整形,+-*/........,多行字符串’‘’ ‘’‘
    • 'dahsdhag', 字符串str ,str+str ,str*int
    • True False bool 布尔值
  • 用户输入input

  • name = input('>>>')  (字符串)
    print(type(name))
    
  • if

    • if 条件:
    • if else:
    • if elif elif.........(顺序,从上到下截胡)
      • if 嵌套

3.今日内容

1.while循环

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

  • what: while 无限循环

  • how:

    • 基本结构:

      while True:
          print('斗牛')
          print('烟火里尘埃')
          print('齐天')
          print('寒鸦少年')
          print('疯人院')
      
    • 基本原理:

      ![img](file:///D:QQ data353913575ImageC2C6D}JA%I9BTP931Q~NG{DWEF.png)

      • 先判断条件是否为True
      • 是True,则进入循环体
      • 执行到循环体底部
      • 继续判断条件,条件成立,进入循环体
    • 循环如何终止:

      1.改变条件:

      flag = True
      while flag:
          print('斗牛')
          print('烟火里尘埃')
          print('齐天')
          flag = False    #变量重新赋值而已
          print('寒鸦少年')
          print('疯人院')
      
      • 标志位 flag = True

        ​ while flag:

        count = 1
        while flag:
            print(count)
            count = count + 1
            if count > 100:
                flag = False
        

      • count直接限制 while

        count = 1
        e = 0
        while count < 101:
            e = count % 2
            if e == 0:
                print(count)
            count = count + 1
        

      2.break : 循环中遇到 break 直接退出循环体

      ![HMREVOF_(VSVSTP4LA`8A4](D:QQ data353913575FileRecvMobileFileImageHMR[EVOF_)VSVSTP4LA`8A4.png)

      • ctrl + / 选择代码变为注释

      • ctrl + . 中英文输入法切换

      • continue 循环底部,返回并判断条件

        flag = True
        while flag:
            print(111)
            print(222)
            flag = False
            continue       #循环底部,并返回判断条件
            print(333)
        

        3.while else

      • while 循环未被 break 打断,则else执行

        count = 1
        while count < 5:
            print(count)
            count = count + 1
        else:
            print(666)
        

      • 4

        count = 1
        while count < 5:
            print(count)
            if count == 2:
                break
            count = count + 1
        else:
            print(666)
        
        

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

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

2.格式化输出

msg = '''---------------info of 刘译蓬---------------
Name  : 刘译蓬
Age   : 27
Job   : Student
Hobbie: girl
---------------end---------------'''

#制作公共模板
#让字符串的某些位置可变成动态传入的
#格式化输出

name = input('请输入您的姓名:')
age = input('请输入您的年龄:')
job = input('请输入您的工作:')
hobbie = input('请输入您的爱好:')

#    % 占位符  s ---> str字符串  d数字  i数字    r

msg = '''---------------info of %s---------------
Name  : %s
Age   : %s
Job   : %s
Hobbie: %s
---------------end---------------'''%(name,name,age,job,hobbie) # % 紧跟

print(msg)
  • 当你的字符串中,想让某些位置变成动态可传入的,首先要考虑到格式化输出.

3.运算符

  • 算数运算符+ -
  • 比较运算符 > ==
  • 赋值运算符 = ,+=
  • 逻辑运算符 and or
  • 成员运算符
i1 = 2
i2 = 3
#print(2**3)
# print(10//3)
# print(10%3)

#print(3 != 4)

# count = 1
# count = count + 1
# count += 1
# print(count)
#and与 or或 not非

#1.在没有()的情况下,优先级not > and > or,同一优先级从左至右依次计算
#情况1:两边都是比较运算
#print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)

#情况2,两边都是整数
#x or y, x为真,值就是x,x为假,值是y。  and 反着记
print(1 or 2)
print(3 or 2)
print(4 or 2)
print(-1 or 2)
print(0 or 2)
#str---> int ; 只能是纯数字组成的字符串
s1 = '00100'
print(int(s1))
#int ---> str
i1 = 100
print(str(i1),type(str(i1)))

#int ---> bool :非零即True , 0为False
i = 0
print(bool(i))
#bool ---> int
print(int(True))  # 1
print(int(False)) # 0

4.编码的初识 重点

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

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

第一版:没有段位

第二版:七位一段

最早期的密码本:

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

    • 0000 0001:a
    • 0000 0101:;

    8位(bit)= 1字节( byte)第一位预留,全是0

    'hello123':8个字节(byte)

  • gbk:只包含英文字母,数字,以及特殊字符和中文。国标

    • 一个英文字母: 1 byte 0000 0001: a
    • 一个中文: 2byte 0000 0001 0100 0001:中 2的16次方=65536个字
  • Unicode:万国码:把世界上所有的文字都记录到这个密码本。

    ​ 起初,一个字符用两个字节表示

    • 0000 0001 0100 0001: a

    • 0000 0001 0100 0001: 中

    后来为了涵盖全部文字:

    • 0000 0001 0100 0001 0000 0001 0100 0001: a

    • 0000 0001 0100 000 10000 0001 0100 0001:中

      浪费空间,浪费资源。

  • Utf-8:

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

    • 0000 0001: a 1 字节

    • 0000 0011 0000 0011: 欧洲 2个字节

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

      重点:

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

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

8bit = 1byte
1024byte = 1KB
1024KB = 1MB
1024MB = 1GB
1024GB = 1TB
1024TB = 1PB
1024TB = 1EB
1024EB = 1ZB
1024ZB = 1YB
1024YB = 1NB
1024NB = 1DB   

7.8Mb= 7.8* 1024 * 1024*8 bit 比特流

4.明日内容

1.二进制与十进制转换

2.str bool int 转换

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

4.for 循环

原文地址:https://www.cnblogs.com/Redbean1231/p/13222199.html