zoukankan      html  css  js  c++  java
  • python数据类型和运算符

    1 bool值类型只有两个值   (True, False)    布尔值

       str    int    bool ()  三种数据类型之间的转化

        str   int()   bool()   本身是内置函数

       srt ---->int      a="6484684"  元素必须是数字,否则报错

        srt----->bool     空串是False,     非0全部为True

        bool---->int      True是1    Fales 是0

       bool-----> str      "True,"    "False"

    2#比较运算符

       >    <         <=       !=

        ==      比较两个对象的值是否相同

         is       比较的是内存地址是否相同

             看内存地址的方法         id(对象)

        c=200

        d=200

        print(c==d)         #比较数值

        print(c    is    d )    #比较内存地址,相当与id(c)==id(d)

    3逻辑运算符      and       or      not

           x  and  y,    x 为真,  值是y ,   x为假,    值是x

           x   or  y ,   x  为真,  值就是x, x为假,  值是y

     比较运算符优先级高于逻辑运算符

          () >not   >and   >or

     如果优先级在同一级,从左往右依次执行

         练习题

          8  and    6

         0  and   8

          6  or   5 

           0  or  7

         7  or  6  and  8     7

        7   or   6  and 8  and  9      7

         7  or   6  and  0  and  9   7

                or  

                   a    or     b   a    为trun则返回a,(一个为真则为真)

                   a  为Fals返回b

               and

                     a   为True 则返回b

                      a 为 False  则返回Fasle  (一个为假则为假)

               not   

                      not  True     ------False

                      not  3  --------False

                      not  0  ---------True

       

      4   算数运算符  +  -    *   /         %  取除       **  平方      //取证

       5  成员运算符      in     not     in

              现在学的只有字符串      x  in  y,    y  中是否包含x

       6  赋值运算符

         =  +=        -=    * =      %=     **=  //=

             a = b 

             b = 3

              a=a+b         #a  +=b

               a  =a-b      #    a-=b

              print(a)

        

        学到的内置函数

          print()

          input()

         type()

           int()

           str() 

          bool()

        

  • 相关阅读:
    【LeetCode】650. 只有两个键的键盘
    【LeetCode】70. 爬楼梯
    【LeetCode】746. 使用最小花费爬楼梯
    【LeetCode】198. 打家劫舍
    【LeetCode】53.最大子序和
    【LeetCode】1056-易混淆数
    【人工智能系列】python的Quepy库的学习
    【计划书】关于运营商的人工智能的想法
    【转】经典!python中使用xlrd、xlwt操作excel表格详解
    转]python 结巴分词(jieba)学习
  • 原文地址:https://www.cnblogs.com/lisen321/p/11685348.html
Copyright © 2011-2022 走看看