• python


    python:
    用户交互:
    等用户输入,做反应;

    username=input("username:")
    password=input("password:")
    print(username,password)

    注释:#
    1.不好理解的地方加注释
    2.中文可用中文,英文,不用拼音
    -----------------------------
    数据类型:
    integer int
    float
    C语言明确告诉计算机是什么类型 int age=12

    python不需要用户写 解释器做了
    >>> age=12
    >>> type(age)
    <class 'int'>

    数据类型:对常用的各种数据类型进行了明确的划分;
    --------------------------------
    python数据类型:
    基本类型:
    1.数字
    整数int 长整型long 浮点型float
    2.字符串
    文本str 字节bytes
    3.布尔
    true false
    数据集:
    1.列表list
    2.元祖tuple (数组)
    3.字典dict
    有序字典 无序字典
    4.集合set
    有序集合 无序集合
    ----------------------------------
    基本类型 - 范围:
    1.int(整型)
    32 -2**31 ~ 2**31-1 即:-2147483648 ~ 214748364
    64 -2**63 ~ 2**63-1 即:-9223372036854775808 ~ 9223372036854775807
    2.long(长整型)
    python2.2起,整数发生溢出,python会自动转换为长整数
    python3起,不在有long型,全部是int
    3.字符串
    '' "" ''' ''' """ """ 都可 单引号=双引号适合单行 多引号写多行

    msg="My name is alice,I'm 22 years old" //单双引号配合使用

    msg='''my name is alice, //多句话,多行
    i'm 22 years old '''
    print(msg)

    msg="my name is alice, //单行话, 表示还没结束,往下一行写
    i'm 22 years old "
    print(msg) //my name is alice,i'm 22 years old

    注意:不加引号的字符串表示变量;name=jack 出错;

    字符串 + 和 *
    >>> name='alcie '
    >>> age='12 '
    >>> name+age
    'alcie 12 '

    >>> name='alice '
    >>> name*10
    'alice alice alice alice alice alice alice alice alice alice '

    注意:只能字符串和字符串+ * 不能跨数据类型
    4.布尔
    true false 逻辑判断
    >>> a=10
    >>> b=12
    >>> a<b
    True
    >>> a>b
    False

    根据条件是否成立,决定走那条路;为了后面的逻辑
    if a>b
    print(a is bigger than b)
    else
    print(a is smaller than b)
    ----------------------------------
    格式化输出:
    name=input("Name:")
    age=int(input("Age:"))
    job=input("job:")

    print(type(name),type(age))

    ##print("--------info of ",name,'---------')
    ##print("Name:",name)
    ##print("Age:",age)
    ##print("Job:",job)
    ##print("--------end---------")

    info='''
    -----info of %s -----
    Name: %s
    Age: %d
    Job: %s
    ----- end -----
    ''' % (name,name,age,job)
    print(info)

    注意:%s(占位符)
    %s =string
    %d=digit
    %f=float
    age=input("Age:") type(age) 是str input输出的都是str s是万能的
    -----------------------------------
    运算符:
    按种类分:算数运算 比较运算 赋值运算 逻辑运算 成员运算 身份运算 位运算

    1.算数运算:
    + - * /
    %(取模) // 奇数%2=1 偶数%2=0
    ** (幂) //2**4=16
    //(取整除) //9//4=2
    2.比较运算:
    ==(等于) != <> (不等于) > < >= <=
    <>(python3中没有,python2有)
    3.赋值运算:
    = += -= *= /= %= **= //=
    4.逻辑运算:
    and or not
    ----------------------------------
    流程控制:
    1.单分支
    age = 12

    if age > 15:
    print("your age is:",age)

    print("-----end-----")

    2.双分支
    age = 12

    if age > 15:
    print("your age is:",age)
    else:
    print("else path")

    print("------end------")

    _username = "alice"
    _password = "123"

    username = input("username:")
    password = input("password:")

    if username == _username and password == _password:
    print("welcome ",_username)
    else:
    print("wrong username or password!")

    3.多分支
    age = 26

    user_guess = int(input("your guess:"))

    if user_guess == age:
    print("猜对了")
    elif user_guess < age:
    print("try bigger")
    else:
    print("try smaller")

    num = int(input("Num:"))

    if num > 100:
    print("成绩最多只能到100")
    elif num >= 90:
    print("A")
    elif num >= 80:
    print("B")
    elif num >= 60:
    print("C")
    elif num >= 40:
    print("D")
    elif num >=0:
    print("E")
    else:
    print("成绩不能是负数")

    -------------------------------------
    总结:
    1.用户交互
    2.数据类型
    3.格式化输出
    4.运算符
    5.流程控制的 单双多分支

  • 相关阅读:
    SpringBoot之Banner介绍
    SpringBoot事件监听机制
    SpringBoot 启动流程图
    ApplicationContextInitializer的理解和使用
    SpringFactoriesLoader解析
    计时器之StopWatch
    ftp上下载文件
    打印两个函数的返回值
    关闭所有已打开的文件和关闭应用
    TypeError: include() got an unexpected keyword argument 'app_name'
  • 原文地址:https://www.cnblogs.com/alice-bj/p/8407035.html
Copyright © 2020-2023  润新知