1. import types
  2.  
  3. aaa = 0
  4. print type(aaa)
  5. if type(aaa) is types.IntType:
  6. print "the type of aaa is int"
  7. if isinstance(aaa,int):
  8. print "the type of aaa is int"
  9.  
  10. bbb = 'hello'
  11. print type(bbb)
  12. if type(bbb) is types.StringType:
  13. print "the type of bbb is string"
  14. if isinstance(bbb,str):
  15. print "the type of bbb is string"
  16.  
  17. #if the type is NoneType,the isinstance does not work
  18. #we should judge the NoneType like below
  19. #if row is None
  20. #if type(row) is types.NoneType
  21.  
  22. #In my opinion,use the types to judge the type of a param is convinient<span style="font-family:Arial;background-color: rgb(255, 255, 255);">, use the isinstance to judge whether a instance is a type of a class or not</span>

Python学习--判断变量的数据类型的更多相关文章

  1. python学习日记(基础数据类型及其方法01)

    数字 int 主要是用于计算的,常用的方法有一种 #既十进制数值用二进制表示时,最少使用的位数i = 3#3的ASCII为:0000 0011,即两位 s = i.bit_length() print ...

  2. javascript重修之书(一):如何判断变量的数据类型

    javascript重修之书(一):如何判断变量的数据类型 一:检测值类型 基本类型:(Undefined.Null.Boolean.Number和String) javascript之所以被称为一门 ...

  3. python学习日记(基础数据类型及其方法02)

    python的变量 python中的变量不需要声明,变量载使用前必须被赋值,变量被赋值以后才会被创建. 在python中变量就是变量,没有数据类型.我们所说的类型是变量所指向内存中的对象的类型. py ...

  4. python中的变量和数据类型

    一.变量定义:变量是计算机内存中的一块区域,存储规定范围内的值,值 可以改变,通俗的说变量就是给数据起个名字. 二.变量命名规则: 1. 变量名由字母.数字.下划线组成 2. 数字不能开头 3. 不可 ...

  5. Python自动化开发-变量、数据类型和运算

    一.变量 变量定义:Variables are used to store infomation to referrenced and manipulated in a computer progra ...

  6. Python如何判断变量的类型

    Python判断变量的类型有两种方法:type() 和 isinstance() 如何使用 对于基本的数据类型两个的效果都一样 type() ip_port = ['219.135.164.245', ...

  7. 【Python学习】Python3 基本数据类型

    参考学习地址:https://www.runoob.com/python3/python3-data-type.html Python3 基本数据类型 Python 中的变量不需要声明.每个变量在使用 ...

  8. python中判断变量的类型

    python的数据类型有:数字(int).浮点(float).字符串(str),列表(list).元组(tuple).字典(dict).集合(set) 一般通过以下方法进行判断: 1.isinstan ...

  9. Python第二章-变量和数据类型

    变量和数据类型 一.什么是变量,常量 思考:程序执行指的是什么? 对数据进行存储处理和计算,最终获得结果,这是程序执行的本质. 变量的概念和在数学中的变量的概念一样的,只是在计算机程序中,变量不仅可以 ...

随机推荐

  1. VISUAL STUDIO 2012下的OPENCV 2.4.7安装过程

    邮箱已经收到了Visual Studio 2013的升级通知,但是很多软件如OpenCV.Qt等都只有VS2012的预编译库,还是懒得升级了(除非VS支持C++11了). 网上搜了一些VS2012(或 ...

  2. Linux 常用小命令

    1.  查看目录的总和 du -sh 路径 2. 查看linux目录下所有某种类型的文件的行数--> 就是想看自己写了多少行代码 find /opt/code/zk_css -name '*.p ...

  3. c算法

    斐波那契 void main() { ]={, }, i; ;i<=;i++) //这里需要注意,for循环虽然<=9, 还有个i++ { a[i] = a[i-] + a[i-]; pr ...

  4. Entries missing in table T028G T-CODE: OT51 SAP 传输配置操作为用户操作 SAP网银接口

    change this setting as a 'current setting' according to SAP note '135028 - Transfer IMG activity to ...

  5. 关于使用mybatis的一个惨痛教训

    事情大概是这样的: 某个时刻之后所有的交易都崩溃了,查看数据库得知所有的数据都变成一样的了!!! 再查看log,发现执行了这样的语句:UPDATE XXX SET c1=v1,c2=v2 ...,没有 ...

  6. HTTP 错误 500.19 配置文件错误 ( 0x8007000d,0x80070032)

    HTTP 错误 500.19 - Internal Server Error无法访问请求的页面,因为该页的相关配置数据无效. 详细错误信息模块 IIS Web Core 通知 未知 处理程序 尚未确定 ...

  7. Drools 语法

    Drools 语法 规则语法 package: package 的名字是随意的,不必必须对应物理路径 import: 导入外部变量 规则的编译与运行要通过Drools 提供的各种API 来实现.API ...

  8. iOS:PSTCollectionView

    https://github.com/steipete/PSTCollectionView Open Source, 100% API compatible replacement of UIColl ...

  9. UNIX环境编程学习笔记(15)——进程管理之进程终止

    lienhua342014-10-02 1 进程的终止方式 进程的终止方式有 8 种,其中 5 种为正常终止,它们是 1. 从 main 返回. 2. 调用 exit. 3. 调用_exit 或_Ex ...

  10. Greenplum-cc-web监控软件安装时常见错误

     错误error: 1.no pg_hba.conf entry for host “::1”, user “gpmon”, database “gpperfmon”, SSL off 解决: vi ...