Python自学笔记(2day)

(1)编码:计算机中=编码全部是用01010101010二进制表示的。

(2)ACSII码:ACSII码一开始是7位数,后来为了拓展转变为8位数,最左边一位为0。

     1byte(字节)=8bit(位)      1024byte=1kb    1024kb=1mb    1024mb=1gb   1024gb=1tb

(3)uicode(万国码):用4个个字节,32位表示一个中文,用不完,然后升级为  utf-8  编码,

    utf-8编码用3个字节,24位表示一个中文。

(4)运算符:%取余, //整除 取商整数部分,  != 不等于

    逻辑运算:and or not  

    优先级:not>and>or  同级别从左至右一次运算

    计算机中:非0数位真True,0为假False

    and:全真为真

    or:一真就为真

    not:非

   列子:

          1.逻辑运算

print(2<3 and 4>3)
#为T
print(2<3 and 4<3)
#为F
print(2<3 or 3>4)
#为T

       2.数字运算

        X or Y,X为真输出X,否则输出Y

        X and Y, X为真输出Y,否则输出X

print(2 or 3)
#2
print(0 or 2)
#2
print(2 and 3)
#3
print(0 and 4)
#0
print(1<3 or 4)
#T
print(1<3 and 4)
#4

 总结:逻辑运算输出True或者False ,数字比较输出数字。

课后习题

#输出1-2+3.....+99的和,不包括88

count=0
sum=0
while count<99:
    count+=1
    if count==88:
        continue
    elif count%2==1:
        sum=sum+count
    elif count%2==0:
        sum=sum-count
print(sum)

    

原文地址:https://www.cnblogs.com/baobaoran/p/9594972.html