zoukankan      html  css  js  c++  java
  • 第二堂课学习

    python学习笔记第二课
    回顾:

    打印 hello world ---> print("hello world")
    变量:存储信息,方便于日后的调用与修改
    常量:固定不变的量,字母大写
    命名规则:
    1 字母数字下划线组成
    2 不能以数字开头,不能包含特殊字符与空格
    3 不能以汉字命名
    4 定义的变量名应该有意义
    5 驼峰式命名,下划线分割单词
    6 不能以关键字命名
    7 变量名区分大小写

    if判断
    第一种if
    if(进行判断):
    执行语句
    else:
    执行语句

    # if...else 成对出现

    a=1
    b=2
    if a<b:
    print("Yes")
    else:
    print("No")

    第二种if
    if(进行判断):
    执行语句
    elif(进行判断):
    执行语句
    elif(进行判断):
    执行语句
    else:
    执行语句

    注释
    单行注释 # 比如 #...
    多行注释 '''...''' ; """..."""

    '''
    b=12
    print("age is",b)
    ---> print("age is"+str(b))

    用户交互
    input 获取用户输入
    input(">>:")

    字符串的拼接
    + 连接两边
    print("abc"+"qwe")

    类型的强制转换
    int(...) # 强制转化为整型
    str(...) # 强制转换为字符串

    a = '12'
    int(a)
    ---> 12

    # 算数运算符
    + - * /
    //(取整) %(取余数)**(指数运算)

    1+2 = 3
    3-2 = 1
    2*6 = 6
    6/3 = 2
    9/2 = 4.5
    9//2 = 4
    9%2 = 1
    2**10 = 1024
    2**3*8 = 40 ---> (2**3)*8
    注意: 为避免产生运算符上的混淆,建议使用()来区分运算等级
    同时应注意 Python只有(),比如"(( ))== [( )]"

    #赋值运算符
    = += -= *= /= %=
    //= **=

    #比较运算符
    false ture
    > < == != >= <=

    #逻辑运算符
    not and or #优先级由左到右
    条件1 and 条件2 全真为真,有假必假
    条件1 or 条件2 一真为真,全假才为假
    not 条件 条件为真,结果为假;条件为假,结果为真


    #表达式与运算符
    1+2*3 这就是一个表达式,这里的乘号和加号叫做运算符,1,2,3称之为操作数
    1+2*3经计算的结果为7;就是1+2*3=7.我们可以将计算结果保存在一个变量里,ret=1+2*3.所以表达式就是由操作数和运算符组成的一句代码或是语句,表达式可以求值,可以放在"="右边,用来给变量赋值


    #While 循环
    while 条件:
    执行循环语句

    #输出1-10
    num = 1

    while num<10
    print(num)
    num+=1

    #输出偶数
    num = 1
    while num<=100
    if num%2 == 0
    print(num)
    num +=1

    #猜年龄
    i = 1
    age = 50
    user_input_age = int(input("Age is:"))
    while(i<100):
    if(user_input_age==age):
    print("Congratulation,you got it")
    break;
    else:
    print("Sorry,you miss it!Maybe,you can try it again ")
    i+=1
    user_input_age= int(input("Age is:"))

    #猜年龄的改进
    age = 50
    flag = True
    while flag:
    user_input_age = int(input("Age is:"))
    if user_input_age == age:
    print("Congratulation,you got it")
    flage = False
    elif user_input_age > age:
    print("Sorry,it is bigger!Maybe,you can try it again ")
    else:
    print("Sorry,it is smaller!Maybe,you can try it again ")
    print("End")

  • 相关阅读:
    测试平台系列(9) 与前端联调注册/登录接口(part 2)
    测试平台系列(8) 与前端联调注册/登录接口(part 1)
    测试平台系列(7) 改造注册接口
    测试平台系列(6) 配置flask-sqlalchemy
    测试平台系列(5) 引入Ant Design Pro
    UICollectionView添加headerView
    iOS UICollectionReusableView xib 拖不了线
    xcode Errors were encountered while preparing your device for development. P
    UICollectionView Cell大小自适应 并靠左对齐最简单的实现
    iOS UICollectionView 一行三个计算 高度
  • 原文地址:https://www.cnblogs.com/Skypeduty1225/p/8338438.html
Copyright © 2011-2022 走看看