zoukankan      html  css  js  c++  java
  • 循环

    一、while 循环

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

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

    基本结构:

    while 条件:
        循环体

    初识循环:

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

    循环如何终止?

    改变条件

    flag = True
    while flag:
        print('狼的诱惑')
        print('我们不一样')
        print('月亮之上')
        flag = False        # 改变了条件
        print('庐州月')
        print('人间')
        
    # 输出
    狼的诱惑
    我们不一样
    月亮之上
    庐州月
    人间

    break:强制退出循环

    flag = True
    while flag:
        print('狼的诱惑')
        print('我们不一样')
        print('月亮之上')
        break               # 从此处退出循环
        print('庐州月')        
        print('人间')
        
    # 输出
    狼的诱惑
    我们不一样
    月亮之上

    二、运算符

    算数运算符 + -,比较运算符 > ==,赋值运算符=,+=,逻辑运算符,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)
    ​
    # 输出
    8
    3
    1
    True
    3
    and or not

    在没有()的情况下,优先级:not > and > or,同一优先级从左至右依次计算

    # 情况1:两边都是比较运算
    print(2 > 1 and 3 < 4 or 4 > 5 and 2 < 1)
    print(True or False)
    ​
    # 输出
    True
    True
    ​
    ​
    # 情况2:两边都是整数
    '''
    x or y , x为真,值就是x,x为假,值是y
    '''
    print(1 or 2)
    print(3 or 2)
    print(4 or 2)
    print(-1 or 2)
    print(0 or 2)
    print(1 and 2)
    ​
    # 输出
    1
    3
    4
    -1
    2
    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

    三、编码的初识

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

    密码本: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个字节

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

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

     

    学习之旅
  • 相关阅读:
    Jquery 的offset与position方法
    HTML精确定位:scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
    js中对日期进行加减
    EditPlus 换行
    constructor属性,valueOf(),toSTring
    浅谈C#增加that关键字
    ASP.NET Global.ascx 事件大全
    Javascript:scrollWidth,clientWidth,offsetWidth的区别
    jquery val() 返回值怎么转换成 javascript 日期类型
    微软宣布Entity Framework 5的性能有了显著提升
  • 原文地址:https://www.cnblogs.com/XiaoYang-sir/p/14637168.html
Copyright © 2011-2022 走看看