zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    数据库的初始创建
    组合总和 II (Leetcode 暴力)
    Leetcode 最大正方形(两种解法)
    Python PyAPNs 实现消息推送
    Windows下nginx+web.py+fastcgi服务搭建
    Python学习预备
    《Effective C++》笔记:IV
    《Effective C++》笔记:III
    《Effective C++》笔记:II
    《Effective C++》笔记:I
  • 原文地址:https://www.cnblogs.com/luoahong/p/9887759.html
Copyright © 2011-2022 走看看