• Day 4 Python语法


    day4思维导图

    一 运算符

    数学运算符 Arithmetic Operators

    比较运算符 Comparison Operators

    These operators compare the values on either sides of them and decide the relation among them. They are also called Relational operators.

    赋值运算符 Assignment Operators

    增量赋值

    #增量赋值
    age =20
    age += 2
    print (age)

    22

    链式赋值

    # 链式复制
    a = b = c = 15
    print(a, b, c)
    print(id(a), id(b), id(c))   #判断id是否相同

    15 15 15
    8791081748576 8791081748576 8791081748576

    交叉赋值

    # 交叉赋值
    m = 10
    n = 20
    m, n = n, m   # 关键步骤
    print(m, n)

    20 10

    解压赋值

    # 解压赋值
    salary = [11, 22, 33, 44, 55] # 常规语法
    mon1 = salary[0]
    mon2 = salary[1]
    mon3 = salary[2]
    mon4 = salary[3]
    mon5 = salary[4]
    print(mon1, mon2, mon3, mon4, mon5)

    mon1, mon2, mon3, mon4, mon5 = salary # 解压运算
    print(mon1, mon2, mon3, mon4, mon5)

    *_, last2, last1 = salary # 占位符
    print(last2)
    _, _, mid3, mid4, _ = salary
    print(mid3)


    11 22 33 44 55
    11 22 33 44 55
    44
    33
    注意点

    上述解压赋值,等号左边的变量名个数必须与右面包含值的个数相同,否则会报错

    逻辑运算符 Logical Operators

    and 与

    or 或

    not 非

    优先级 priority

    not>and>or

    短路运算

    and 遇到一个为假即为假

    or 遇到一个为真即为真

    二 流程控制之if判断

    多分支注意点:elif成立的条件必须为前一句不生效

     #  简易成绩查询器
    score = float(input(('请输入成绩: ')))
    if score >= 90:
      print('优秀')
    elif score >= 80:
      print('良好')
    elif score >= 60:
      print('及格')
    else:
      print("不及格")

     

    三 用户输入功能

    输入 input函数

    注意点

    input输入的内容为字符串,如果是其他类型要注意转换

    格式化输出 print函数

     

    四 补充

    1.符号学 Semiotics

    符号学(征象学)包括三个分支:语用学(pragmatics)、语义学(semantics)、语法学(syntactics)

    征象有三个意义化的层次:这三层意义由外在到深层隐晦依序为明示义(denotation)、隐含义(connotation)以及意识形态(ideology)。

    第一层明示义:征象具外观之具体、外显且可见的明显意义,容易转化为符号。

    第二层包含隐含义与迷思(myth):一个征象的意义并不是因为他与世界中的某样事物有绝对的对应关系,而是以彼此之间的关系来产生意义的,所以将第一层的符号化体系嵌进文化价值体系之内,而有使征象有其符号的意义。

    第三层意识形态:反映出文化用来组织和解释现实的广泛规则。

    https://zh.wikipedia.org/wiki/%E7%AC%A6%E8%99%9F%E5%AD%B8

    2.隐式布尔值

    万物皆可布尔

    除了0, None, 空,这三个为假,其余皆为真

     

  • 相关阅读:
    053(五十六)
    【leetcode❤python】 Maximum Depth of Binary Tree
    【leetcode❤python】Find the Difference
    【leetcode❤python】Binary Watch
    【leetcode❤python】Convert a Number to Hexadecimal
    【leetcode❤python】83. Remove Duplicates from Sorted List
    【leetcode❤python】66. Plus One
    【leetcode❤python】70. Climbing Stairs
    【leetcode❤python】409. Longest Palindrome
    【leetcode❤python】387. First Unique Character in a String
  • 原文地址:https://www.cnblogs.com/fengshili666/p/14154898.html
Copyright © 2020-2023  润新知