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

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

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

    str()       int()       bool()      本身是内置函数
    str---->int           a = "6484684"      元素必须是数字,否则报错
    str----->bool       空串是False      不为空全部为True
    int----->bool       0为False    ,非0全部为True
    bool--->int        True  是1    False是0
    bool---->str        "True" ,  " False"
     
    2,比较运算符
        >   <    >=     《=     !=
       ==      比较俩个对象的值是否相同
       is    比较的是内存地址是否相同
        看内存地址的方法          id(对象)

     

    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为True则返回a,(一个为真则为真)

                      a  为 False返回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,赋值运算符

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

     

    学到的内置函数

      print()

      input()

      type()

      int()

       str()

       bool()

       id()

    小数据池:  只在str,int中存在的

         小数据池作用:  (为了节省内存而存在)

         数据  -5 ---256  之间的值共用一个内存地址

         str  ,   空或者一位 (包括特殊字符)也就是共用一个内存

              如果多位并且包括特殊字符不共用内存

     

     为空时,为true

     

     在python交互式时,变量可以直接输出,不用借助print

     

     

     

      

     

     

     

        

         

     

     
  • 相关阅读:
    web.xml配置详解(转载)
    http协议无状态中的 "状态" 到底指的是什么?!(转载)
    sublime配置python运行环境
    Eclipse下载安装教程
    局域网访问文件共享了访问不了解决方法
    ThreadLocal实现线程级上下文
    Spring中ApplicationEvent和ApplicationListener封装
    MySQL根据出生日期计算年龄的五种方法比较
    常用正则
    java.lang.OutOfMemoryError: PermGen space有效解决方法
  • 原文地址:https://www.cnblogs.com/zuohangyu123/p/11685263.html
Copyright © 2011-2022 走看看