• python学习第二天


    1. 编码问题

    • 最初的编码是ascii,一个字节能够表示所有的英文,特殊字符,数字等等。
    • unicode一个中文字符用四个字节表示。
    • 升级版utf-8,一个中文字符用三个字节表示。
    • 国内用的是gbk,一个中文用两个字节表示。

    2. 格式化输出

    已%为占位符与转移符号

    name = input('请输入姓名')
    age = input('请输入年龄')
    height = input('请输入身高')
    msg = "我叫%s,今年%s 身高 %s 学习进度为3%%s" %(name,age,height)
    print(msg)

    3。 逻辑运算

    优先级,()> not > and > or

    int ----> bool 非零转换成bool True 0 转换成bool 是False

    x or y x True,则返回x,与and相反(针对数字)

    1,3>4 or 4<3 and 1==1
    2,1 < 2 and 3 < 4 or 1>2 
    3,2 > 1 and 3 < 4 or 4 > 5 and 2 < 1
    4,1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8
    5,1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
    6,not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6

    结果:False,True,True,False,False,False

    数字的逻辑运算遵循下列原则:

    数字的逻辑运算原则

    8 or 4 -->8
    0 and 3-->0
    0 or 4 and 3 or 7 or 9 and 6-->3

    4. while-else

    当while循环正常终止时,则执行else语句。

    正常时

    count = 0
    while count <= 5 :
        count += 1
        print("Loop",count)
    
    else:
        print("循环正常执行完啦")
    print("-----out of while loop ------")

    不正常时

    count = 0
    while count <= 5 :
        count += 1
        if count == 3:break
        print("Loop",count)
    
    else:
        print("循环正常执行完啦")
    print("-----out of while loop ------")
  • 相关阅读:
    Vue的一些记录
    使用AndroidKiller进行APK反编译
    Clickhouse 分组查询排序取第一条数据
    onnx
    cross_entropy
    diffusion model
    无法解析类型 java.util.Map$Entry。从必需的 .class 文件间接引用了它
    redis key迁移、复制
    Linux查看网络事情情况
    [CentOS7]升级SSH9.0p1
  • 原文地址:https://www.cnblogs.com/wujunjie-sir/p/9152708.html
Copyright © 2020-2023  润新知