zoukankan      html  css  js  c++  java
  • day3 编码的理论知识

    1、电脑的储存是以二进制的方式储存,换算单位如下:

      00000001    8位bit               ==1个字节(byte)

           1byte            1024byte(字节)==1kb

            1kb               1024kb             ==1MB

            1MB              1024MB           ==1GB

            1GB              1024GB           ==1TB

    2、编码的发展史:ascii——万国码(unicode)——utf-8

            ascii:一个字节表示所有的英文,特殊字符,数字等;

            万国码:四个字节表示一个中文(2**32);

            utf-8    :三个字节表示一个中文;(中文有九万多字,2**24);

           (中国国内曾经使用的gbk   ,一个中文两个字节(远远不够,现在极少人使用))

    3、逻辑运算的初始

    逻辑运算符的优先级:

           (1)   ()>not>and>or  同一优先级从左往右计算

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

        (2)   逻辑运算中0为False,其余数字则为Ture

                    x or y , x为真,值就是x,x为假,值是y;

                        x and y, x为真,值是y,x为假,值是x。

    print(0 or 2)
    print(4 or 3)
    print(0 and 4)
    print(1 and 0)
    
    2
    4
    0
    0

    print(3<1 or 3>2)
    print(4>3 and 4>4)

    True
    False

     

           4、int 与bool值之间的换算

          int-------bool

    a=bool(1234)
    b=bool(0)
    c=bool(1 and 2)
    d=bool(0 or 1)
    print(a,b,c,d)
    
    True False True True

       bool---------int

    a=int (True)
    b=int (False)
    print(a,b)
    
    1 0

    5、in 和 not in的运算

    while True:
        comment=input("请输入你的评论:")
        if (""in comment)or (""in comment)or(""in comment):
            print("对不起您输入的有非法字符,请重新输入")
            continue
        else:break
    print("评论成功!")
    a="12344546"
    print("1"not in a)
    print("2"in a)
    
    False
    True
  • 相关阅读:
    铁轨
    POJ 2385 -- Apple Catching
    POJ 3258 -- River Hopscotch
    POJ 1469 -- COURSES (二分匹配)
    POJ 2349 -- Arctic Network
    最小生成树
    NOIP200703守望者的逃离
    NOIP200706字符串的展开
    POJ 1036 -- Gangsters
    POJ 1952 -- BUY LOW, BUY LOWER
  • 原文地址:https://www.cnblogs.com/number1994/p/7846304.html
Copyright © 2011-2022 走看看