py基础,和运算符简单应用

dy2基础+运算符--课程笔记

内容回顾补充

回顾

  • 字符是指在字符串中其中一个字母汉字等,,,的单位名称
  • 字节是指8位的01010101
  • 位代表字节其中一个0或者1
  • 内存,计算时要用到unicdoe编码
  • 1553735176435
  • (字符串可以比较,比较字节二进制码)数字比较全部转化书记进行比较

补充

  • if嵌套:10086实例1553737425493

今日内容

一,循环

1.循环语句

while Tuer:                        死循环,永远成立
    print("人生苦短")               
while 1 > 0                        while后面加条件
    print("人生苦短")
 

count = 1                          每次count加1,到输出10停止
while count <= 10:
    print(count)
    count = count + 1

pass

  • 跳过这次输出

    count = 1
    while count <= 10:
        if count = 7:
            pass
        else:
            print(count)
        count = count + 1

break

  • 终止当前循环

    count = 1
    while Ture :
        print(count)
        if count = 10:
          break
        count = count + 1

continue

  • 跳出本次循环

    count = 1
    while True:
        if count == 7:
            count = count + 1
            continue
        else:
            print(count)
        count = count + 1
  • while else,不在满足while循环条件时触发,或条件等于False触发

    count = 1
    while count < 10:
        print(count)
        count = count + 1
    else:
        print("完成")

2,总结

  • while基本结构
  • break
  • contiunue
  • while else

二,字符串格式化

  • \n 换行符

  • %s 占位符

    mm = "我是%s,年龄%s" %(fmx,20,)
    print("mm")
  • %d 占位符d

  • 在作占位时要输出”%“需要%%可以打印出一个百分号

    name = fmx
    mm = "%s手机电量100%%" %(name)

三,运算符

基础运算符

``python
count = count + 1 == count += 1
```

1553745704336

逻辑运算

  • 数字转布尔值,除0都是转换成Ture ,0是Fales

  • 字符串转布尔值,除空都是Ture,空字符是Fales

  • 布尔值转换成数字,Ture转换成1 ,Fales转换成0

  • 布尔值转换为字符串,为字符串本身

  • 对于 or,如果有遇到 1 or 9 如果都为Ture取第一个,如果是假的则取第二个值

    • vl = 1 or 9 print(vl) 1

    • vl = 0 or 9 print(vl) 9

    • vl = 0 or ”“ print(vl) ”“

四,编码

编码扩展

  • ascli
  • unicode
    • ecs2 2位字节,曾经用
    • ecs4 4位字节,现在用
  • utf-8
  • utf-16
  • GBK 中文两字节,GBKK2312的升级版,亚洲在用
  • GBK2312 中文两字节

单位转换

猜你喜欢

转载自www.cnblogs.com/ffmmxx/p/10626019.html