zoukankan      html  css  js  c++  java
  • python 变量以及循环

    print(“hello world”)
    变量 : 存储信息的,日后被调用、修改操作
    常量: 固定不变的量,字母大写
    命名规则:
    1. 字母数字下划线组成
    2. 不能以数字开头,不能含有特殊字符和空格
    3. 不能以保留字命名
    4. 不能以中文命名
    5. 定义的变量名应该有意义
    6. 驼峰式命、 下划线分割单词
    7. 变量名区分大小写
    a=1
    b=2
    if a<b:
    print("Yes")
    print("Yes")
    print("Yes")
    print("Yes")
    else:
    print("No")
    a=1
    b=2

    if a>b:
    print("Yes")

    elif a==b:
    print("第三")

    else:
    print("any")


    if 条件1:
    自拍
    elif 条件2:

    else:
    跳舞


    # 单行注释
    '''多行注释'''
    """ 多行注释 """


    input()


    "abc" + "qwe"

    file.py
    文件的扩展名:
    .py : python的程序文件
    .txt : 文本文件
    pdf chm html doc xml xls ppt


    jpg png gif jpeg bmp
    avi rmvb MP4 mkv 3gp
    WMV MP3 flue mid

    True 真 正确的
    False 假 错误的


    a
    b = 100
    c = 1000

    if b <= a <= c:
    print("True")

    num number

    num1 = intpu("Num1:")
    num2 = intpu("Num2:")
    num3 = intpu("Num3:")

    输出三个数字中的最大值/最小值

    if num1>num2>num3:
    #num1最大

    else:
    #num1<num2

    if num1>num2>num3 #num1最大
    elif num1>num3>num2 #num1最大
    elif num2>num1>num3 #num2最大
    elif num2>num3>num1 #num2最大
    elif num3>num2>num1 #num3最大
    else

    num3>num1>num2 #num3最大

    num1 num2 num3

    max_num =0

    if num1>num2:
    max_num= num1
    if max_num > num3:
    print("Max NUM is",max_num)
    else:
    print("Max NUM is",num3)
    else:
    max_num = num2
    if max_num > num3:
    print("Max NUM is",max_num)
    else:
    print("Max NUM is",num3)


    num += 1 等价于 num = num + 1
    num -= 1 等价于 num = num - 1
    num *= 2 等价于 num = num * 2
    num /= 2 等价于 num = num / 2
    num //= 2 等价于 num = num // 2
    num %= 2 等价于 num = num % 2
    num **= 2 等价于 num = num ** 2


    and 且,并且
    只有两个条件全部为True(正确)的时候, 结果才会为True(正确)


    条件1 and 条件2
    5>3 and 6<2 True


    or 或,或者
    只要有一个条件为True,则结果为Ture,
    5>3 or 6<2
    真 或 假

    not

    not 5>3 == False
    not 5<3 == True


    a>b and (c>d or (not f))


    (not (not True)) or (False and (not True))


    条件1 and 条件2
    条件1 or 条件2
    短路原则
    对于and 如果前面的第一个条件为假,那么这个and前后两个条件组成的表达式 的计算结果就一定为假,第二个条件就不会被计算

    对于or
    如果前面的第一个条件为真,那么这个or前后两个条件组成的表达式 的计算结果就一定为真,第二个条件就不会被计算

    True or True and False


    猜年龄

    age = 50

    user_input_age = int(input("Age is :"))

    if ....

    while 循环


    while 条件:
    print("any")
    print("any")


    num = 1

    while num<10: # 2
    print(num) # 2
    num+=1 # 3
    if num == 9: # 3
    break

    num = 1

    while num<=100: # num<=100 等价于 True
    # while num<=100: 等价于 while True:
    if num%2 == 0:
    print(num)
    num += 1


    num = 1

    while num<=100:
    if num%2 == 1:
    print(num)
    num += 1



    age = 50

    #user_input_age = int(input("Age is :"))

    flag = True

    while flag:
    user_input_age = int(input("Age is :"))
    if user_input_age == age:
    print("Yes")
    flag =False
    elif user_input_age > age:
    print("Is bigger")
    else:
    print("Is smaller")


    print("End")

    break # 终止
    age = 50

    #user_input_age = int(input("Age is :"))

    #flag = True
    # break
    while True:
    user_input_age = int(input("Age is :"))
    if user_input_age == age:
    print("Yes")
    break
    elif user_input_age > age:
    print("Is bigger")
    else:
    print("Is smaller")


    print("End")

    continue 继续


    if a>b and d<f or 5>3 and d == e:
    ......


    while 条件:
    ....
    else:
    ....

    statement 语句


    num = 1
    while num <= 10:
    num += 1
    if num == 5:
    break
    print(num)
    else:
    print("This is else statement")

     while 条件1:

    .....
    while 条件2:
    ....

  • 相关阅读:
    PLSQL设置数据库选项
    Oracle 11g客户端下载地址
    js将html转换为纯文本
    创建 dblink
    网页禁用表单的自动完成功能禁用密码自动填充autocomplete
    解决oracle11g的ORA-12505问题
    Linux的XServer
    Qt移植对USB鼠标键盘、触摸屏的支持
    Qt5.2.1交叉编译,带tslib插件
    ubuntu 12.04 桌面版关闭图形界面
  • 原文地址:https://www.cnblogs.com/gerenboke/p/11771997.html
Copyright © 2011-2022 走看看