• Python基础【day02】:数据运算(二)


    本节内容

    1. 数据运算
    2. 表达式while 循环

    一、数据运算  

    算数运算:

    比较运算:

    赋值运算:

    逻辑运算:

    成员运算:

    身份运算:

    位运算:

    #!/usr/bin/python
      
    a = 60            # 60 = 0011 1100
    b = 13            # 13 = 0000 1101
    c = 0
      
    c = a & b;        # 12 = 0000 1100
    print "Line 1 - Value of c is ", c
      
    c = a | b;        # 61 = 0011 1101
    print "Line 2 - Value of c is ", c
      
    c = a ^ b;        # 49 = 0011 0001 #相同为0,不同为1
    print "Line 3 - Value of c is ", c
      
    c = ~a;           # -61 = 1100 0011
    print "Line 4 - Value of c is ", c
      
    c = a << 2;       # 240 = 1111 0000
    print "Line 5 - Value of c is ", c
      
    c = a >> 2;       # 15 = 0000 1111
    print "Line 6 - Value of c is ", c

    运算符优先级:

    二、while loop   

     有一种循环叫死循环,一经触发,就运行个天荒地老、海枯石烂。

    海枯石烂代码

    1
    2
    3
    4
    5
    count = 0
    while True:
        print("你是风儿我是沙,缠缠绵绵到天涯...",count)
        count +=1
        

    其实除了时间,没有什么是永恒的,死loop还是少写为好 

    上面的代码循环100次就退出吧

    count = 0
    while True:
        print("你是风儿我是沙,缠缠绵绵到天涯...",count)
        count +=1
        if count == 100:
            print("去你妈的风和沙,你们这些脱了裤子是人,穿上裤子是鬼的臭男人..")
            break

    回到上面for 循环的例子,如何实现让用户不断的猜年龄,但只给最多3次机会,再猜不对就退出程序。

    count = 0
    while True:
        print("你是风儿我是沙,缠缠绵绵到天涯...",count)
        count +=1
        if count == 100:
            print("去你妈的风和沙,你们这些脱了裤子是人,穿上裤子是鬼的臭男人..")
            break
  • 相关阅读:
    解决无法安装Microsoft .Net Framework 3.5
    day11-15,装饰器
    Xmanager Power Suit 6.0.0009 最新版注册激活
    eth
    MySql 8.0 版本使用navicat连不上解决
    day11
    Mybatis使用规则
    nginx的基本配置
    Mybatis分页插件PageHelper使用
    dubbo的使用
  • 原文地址:https://www.cnblogs.com/luoahong/p/9887759.html
Copyright © 2020-2023  润新知