(5)我们一起学Python;常用操作符

基础的东西总得学一遍,对于学过C的同学可能学起Python来比较简单。我们来看一下常用的操作符:

①+-*/其中除法不同,在Python3中  /  得到的是浮点数。想要地板除法应该使用      //

②优先级问题

    -3*2 + 5/-2 -4     是可以正常运行的,-2不用加括号

    >>> -3*2 + 5/-2 -4

    -12.5


    >>> -3**2        幂运算符 右结合性,先运算 (3^2)再*(-1)

    -9


    >>> 3**-2        确认是  右结合性,没毛病
    0.1111111111111111

③比较操作符

④裸逻辑操作符

         >>> (3<4)and(4<5)
        True

    >>> 4 and 9
    9


     >>> not 2        not运算符 取反
    False

⑥优先级排序

猜你喜欢

转载自blog.csdn.net/weixin_34981646/article/details/80722544