Python运算符与编码

while循环

1.基本循环while 条件:

      
 循环体
 
 如果条件为真,那么循环则执行
 如果条件为假,那么循环不执行
while循环代码体现形式
while 3>2: print('在人间')

  num = 1
  while num<101:
  print(num)
  num = num + 1

  break 终止
  continue 跳出本次循环,继续下次循环
  条件 可以控制while循环

2.格式化输出

  msg = '你好%s,我是%s'%('少年','meet')
  print(msg)

  %s %d== %i 占位 d和i必须放入的是整型 %s是不是放任何东西
  %(xx,oo)
  数量要一一对应
  在格式化中使用%的时候需要转义 %%

3.运算符 

    比较运算符
    > < >= <= == !=
    算数运算符
    + - * / ** % //
    赋值运算符
    += -= *= /= //= **= %=
  

    a = 10
    b = 20
    a+=1 # a = a + 1
    a-=1 # a = a - 1
    a*=1 # a = a*1
    a /= 1 # a = a/1
    print(a) # python2中除法得到的是整数,python3中除法得到的是浮点数
    a//=1 # a = a//1
    print(a)
    a**=1 #a= a** 1
    print(a)
    a%=1 # a = a%1
    print(a)


成员运算符 in not in

    msg = '出口数据,健康时代,BBS的成本'
    s = input("请输入内容:")
    if s not in msg:
      print('不在了')
    else:
      print("在了")


    逻辑运算符
    not    and    or

() > not > and > or
if 3>2 and 5>4:  # 真 and 真  俩个都为真才是真
print("成立")

if 3>2 or 5<3: # 真 or 假 也是真 只要有一个是真就是真
# print("成立")

if not 3>5: # 碰到not 就反着来 实例 not 真 就是假
print("成立")


print(bool(8))

print(9 and 6) 官方说明数字运算and都为真的时候取and后边的数字

print(-1 and 0) # 数字and只有有一个假的,就取假的

print(9 or -9) # 官方说明数字运算or都为真的时候取or前面的数字
or有一个为真就取真

  

 4.初识编码

    ascii 美国 256 没有中文  
        一个字节  8位    
    gbk 中国   
        中文 2字节  16位 
        英文 1字节  8位
    unicode 万国码  
        2个字节     16位
        4个字节     32位
    utf-8 可变编码    
        英文 1字节  8位
        欧洲 2字节  16位
        亚洲 3字节  24位
        

        
    单位转化
    # bit 位
    # bytes 字节

    # 1B == 8bit
    # 1024B = 1kB
    # 1024kB = 1MB
    # 1024MB = 1GB
    # 1024GB = 1TB
原文地址:https://www.cnblogs.com/YZL2333/p/10191936.html