zoukankan      html  css  js  c++  java
  • python全栈学习 day02

    pycharm 安装设置:

     按照百度百科或者官网介绍下载,安装.

    激活步骤

    1:改host

    2.输入激活信息,注意有效期.

    python 逻辑运算符://返回的均为bool值

    与 and

    A and B

    或 or

    A or B

    非 not

    not A

     格式化输出:

    name = input("your name is: ")
    age = input("your age is: ")
    height = input("your height is: ")
    msg = '我叫%s,今年%s,身高%s' % (name, age, height)
    print(msg)
    转义符 : %% == %
    while else:
    如果while没有被break打断就走else; 打断了就不走else, 直接跳出整个循环
    注意:while 和 else同级;
    且是把while所有循环走完 再走else
     
    count = 0
    while count <= 5:
        count += 1
        if count == 3:
            break
        print("Loop",count)
    
    else:
        print("Loop is succeed over")
    print("------ out of the while loop ------")

    结果:

    count = 0
    while count <= 5:
        count += 1
        if count == 3:
            pass
        print("Loop",count)
    
    else:
        print("Loop is succeed over")
    print("------ out of the while loop ------")

    结果:

     
    运算符: // 整除运算符,返回商的整数部分
    优先级:比较运算符 > 逻辑运算符
    优先级: ( ) > not > and > or
    同一优先级,从左至右运算
    x or y ; x为真(x非零),则返回x
     
    print(2 or 1)

    返回:2

    x and y ; x为真(x非零),则返回y
     
    print(2 or 1)

    返回结果为: 1

    比较运算符和逻辑符合混合运算时: 返回的值看最终运算时的 运算符 决定
    例子1: 
    print(2 or 1 < 3)

    分析: 首先看 比较运算符(大于符号: >)优先级更高,所以整理后原式:

    print( 2 or False)

    根据OR的运算规则,结果返回为:2

    例子2: 

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

    分析: 依旧是根据优先级,首先计算比较运算符:

    print(False and 3 or 4 and False or not 5)

    再根据逻辑优先级运算 : not > and > or

    print(False and 3 or 4 and False or False)
    print(False  or  False or False)

    结果为: false

    例子3:

    print(2 or 1 < 3 and 2)

    分析: 

    第一步:计算比较运算:

    print(2 or True and 2)

    第二步:计算优先的and:

    print(2 or  2)

    第三步:计算or出结果:

    2

  • 相关阅读:
    python操作csv,对比两个csv文件某列值
    监控端口和僵尸进程脚本
    openldap创建只读账号
    shell 判断文件内容是否改变
    golang调用shell命令标准输出阻塞管道
    fexpect 源码
    python pexpect 免交互自动恢复gitlab数据
    consul client agent 本地读取key value
    pip 安装三方库报超时
    微信小程序滚动tab的实现
  • 原文地址:https://www.cnblogs.com/77-is-here/p/10342905.html
Copyright © 2011-2022 走看看