zoukankan      html  css  js  c++  java
  • while循环.格式化输出.运算符.编码初识.

    一.
    while 3>2: # 真实条件
    print('好嗨哟')
    print('你的骆驼')
    print('在人间')

    num = 1
    while num<11:
    print(num)
    num = num+1 变量都是先执行等号右边的然后在执行等号左边的。
    倒序
    a = 5
    while a:
    print(a)
    a = a-1
    正序
    a = 1
    while a <= 5:
    print(a)
    a = a + 1

    print(1)
    while True:
    print("痒")
    print("鸡你太美")
    print("卡路里")
    print("好运来")
    print("小三")
    print("小白脸")
    print("趁早")
    print("过火")
    print(2)

    falg = True
    while falg:
    print(1)
    print(2)

    print(bool(0))
    数字中非零的都是True

    正序的示范
    count = 1
    while count <= 5:
    print(count)
    count = count + 1

    倒序的示范
    count = 5
    while count:
    print(count)
    count = count - 1

    正序打印从 25 - 57
    count = 25
    while count <= 57:
    print(count)
    count = count + 1

    倒序打印从 57 - 25
    count = 57
    while count >= 25:
    print(count)
    count = count - 1

    break
    continue

    while True:
    print(123)
    print(234)
    break # 终止当前循环,break下方的代码不会进行执行
    print(345)
    print(1111)

    while True:
    print(123)
    print(234)
    print(345)

    while True:
    print(123)
    print(234)
    continue
    continue 伪装成循环体中的最后一行代码(跳出当前循环继续下次循环)
    continue 下面的代码不会执行
    print(345)
    print(1111)

    while else

    while True:
    print(111)
    break
    else:
    print(222)

    while True:
    print(111)
    break
    print(222)

    二.

    a = "------------- info -------------"
    b = "name:"
    c = "age:"
    d = "job:"
    e = "-------------- end -------------"
    name = input("name")
    age = input("age")
    job = input("job")
    print(a + " " + b + name + " " + c + age + " "+ d + job + " " +e)

    s = """ ------------- info -------------
    name:%s
    age:%s
    job:%s
    -------------- end -------------
    """
    name = input("name")
    age = int(input("age"))
    job = input("job")
    print(s%(name,age,job))

    num = input('学习进度:')
    s11 = "大哥黑的学习进度为:%s %%"
    print(s11%(num))

    s = f"今天下雨了{input('>>>')}"
    print(s)

    s11 = "大哥黑的学习进度为:%s"
    print(s11%("不错"))

    s = f"{1}{2}{3}"
    print(s)

    三.

    算数运算符

    / python2获取的值是整数,python3获取的是浮点数(小数2.5)
    print(5/2)
    //(整除-- 地板除)
    print(5 // 2)
    ** 幂(次方)
    print(3**2)
    % 模 (取余)
    print(5 % 2)

    比较运算符

    <
    == (等于)
    != (不等于)

    =
    <=

    赋值运算符

    = 赋值
    += 自加
    a = 10
    a += 1 # a = a + 1
    print(a)
    -= 自减
    *= 自乘
    a = 10
    a *= 2 # a = a * 2
    print(a)
    /=
    //=
    **=
    %=

    逻辑运算符

    and (与/和)
    or (或)
    not (非)

    print(3 and 4)
    print(0 and 4)
    print(0 and False)

    and 都为真的时候取and后边的值
    and 都为假的时候取and前面的值
    and 一真一假取假的

    print(3 and 5 and 9 and 0 and False)
    print(5 and False and 9 and 0)
    print(1 and 2 and 5 and 9 and 6)

    print(1 or 0)
    print(1 or 2)
    print(0 or False)

    or 都为真的时候取or前边的值
    or 都为假的时候取or后面的值
    or 一真一假取真的

    print(1 or 9 or 4 or 0 or 9)
    print(not False)

    () > not > and > or
    从左向右执行
    print(9 and 1 or not False and 8 or 0 and 7 and False)

    成员运算符
    in 存在
    not in 不存在

    s = "alexdsb"
    if "sb" not in s:
    print(True)
    else:
    print(False)

    四.

    今 0101
    天 0110
    晚 0010
    上 0001
    去 1001
    便 1000
    利 0100
    店 1111
    00000101 00000110 0010000110011001

  • 相关阅读:
    10.17 作业
    10.12 classmethod,staticmethod,反射,魔法方法
    10.11 组合,封装,多态
    10.11 作业
    day20 作业
    10.10 类的继承,继承关系,派生,新式类,经典类
    10.9 类,对象,查找顺序,对象绑定方法
    day 55小结
    day 54小结
    day 53小结
  • 原文地址:https://www.cnblogs.com/sundawei7/p/11149121.html
Copyright © 2011-2022 走看看