python 判断参数为Nonetype类型或空的实例

yipeiwu_com7年前Python基础

Nonetype和空值是不一致的,可以理解为Nonetype为不存在这个参数,空值表示参数存在,但是值为空

判断方式如下:

if hostip is None:
    print "no hostip,is nonetype"
elif hostip:
    print "hostip is not null" 
 else:
    print " hostip is null"

以上这篇python 判断参数为Nonetype类型或空的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Django中celery执行任务结果的保存方法

如下所示: pip3 install django-celery-results INSTALLED_APPS = ( ..., 'django_celery_results',) #...

python自定义线程池控制线程数量的示例

1.自定义线程池 import threading import Queue import time queue = Queue.Queue() def put_data...

Python any()函数的使用方法

描述: 如果iterable的任何元素为true,则返回true。如果iterable为空,则返回false。相当于: def any(iterable): for elemen...

tornado框架blog模块分析与使用

复制代码 代码如下:#!/usr/bin/env python## Copyright 2009 Facebook## Licensed under the Apache License...

Django objects的查询结果转化为json的三种方式的方法

Django objects的查询结果转化为json的三种方式的方法

第一种方式: 利用seriallizers 这个方法,官网的解释说:将复杂的数据结构变成json、xml或者其他的格式 import json from django.core...