import types  

aaa = 0  
print type(aaa)  
if type(aaa) is types.IntType:  
    print "the type of aaa is int"  
if isinstance(aaa,int):  
    print "the type of aaa is int"  

bbb = 'hello'  
print type(bbb)  
if type(bbb) is types.StringType:  
    print "the type of bbb is string"  
if isinstance(bbb,str):  
    print "the type of bbb is string"  

#if the type is NoneType,the isinstance does not work  
#we should judge the NoneType like below  
#if row is None  
#if type(row) is types.NoneType  

#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>  

输出结果

7

转载:http://blog.csdn.net/gukesdo/article/details/7064868

centos7安装python3.8

1.安装python 依赖 sudo yum -y install epel-release sudo yum -y update 安装完后可以 reboot 重其服务器,非必须。 2.安装gcc编译环境等等 sudo yum -y gro...

阅读全文

python清空文件夹下log文件

#!/usr/bin/python import os import sys files_list = [] def print_files(path): lsdir = os.listdir(path) dirs = [i for i in lsdir if os.path...

阅读全文

python paramiko(SFTP) 相关文档

python paramiko SFTP文档地址: http://docs.paramiko.org/en/2.4/api/sftp.html import paramiko host = "THEHOST.com" #...

阅读全文

1 条评论

回复 koukou 取消回复