pythonpython 判断变量类型型时,为什么不推荐使用type方法

python判断变量类型时,为什么不推荐使用type方法_百度知道
python判断变量类型时,为什么不推荐使用type方法
提问者采纳
type(变量); 也就是说变量的类型,根据给出的赋值语句决定; 在Python里面变量在声明时,输出的结果就是变量的类型,变量的类型是动态指定的,不需要指定变量的类型方法如下
来自团队:
为您推荐:
其他1条回答
也是可以的,就是个效率和准确率的考虑吧
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁> Python的三个帮助函数type:查看指定变量的类型,如>>>type(dog
Python的三个帮助函数type:查看指定变量的类型,如>>>type(dog
lijiawei_ & &
发布时间: & &
浏览:208 & &
回复:0 & &
悬赏:0.0希赛币
Python的三个帮助函数
  type:查看指定变量的类型,如
  $>>$ type(dog);
&class 'type'&
$>>$ type('a');
&class 'str'&
  help:查看指定变量的详细介绍,如:
  $>>$ class man:
def a(self):
print('kkk')
$>>$ help(man);
Help on class man in module __main__:
class man(builtins.object)
Methods defined here:
----------------------------------
Data descriptors defined here:
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
$>>$ help('a');
bigger than 5
Help on module a:
e:\xuhs\python31\a.py
$>>$ help('bb');
no Python documentation found for 'bb'
  dir:查看指定变量可用的属性或方法,如:
  $>>$ dir(man);
['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'a']
$>>$ man.__class__
&class 'type'&
$>>$ dir(123);
['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'imag', 'numerator', 'real']
$>>$ dir('abc');
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
  由例子可以看出,type的功能比较简单,dir和help功能比较丰富,dir列举出指定变量可用的属性及方法,help不仅列举出可用的属性及方法,还加以详细说明。
本问题标题:
本问题地址:
温馨提示:本问题已经关闭,不能解答。
暂无合适的专家
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&二次元同好交流新大陆
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
&&& import types &&& type(x) is types.StringType &
#判断abc是否是字符串,是的话返回True &&& type(x) is types.IntType&
#判断x是否是整数方法二: &&& isinstance( value, type)
#判断value是否是type类型,如果是返回True方法三: &&& type(x) == type(1)
#判断x是否是整形, &&& type(x) in (type(u''), type(''))
#判断x是否是unicode 或者是string 类型
阅读(1750)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'python 判断 类型(type)的方法(ways)',
blogAbstract:'方法一:\t&&& import types\t&&& type(x) is types.StringType &\t\t#判断abc是否是字符串,是的话返回True\t&&& type(x) is types.IntType&\t\t\t#判断x是否是整数方法二:\t&&& isinstance( value, type)\t\t\t#判断value是否是type类型,如果是返回True方法三:\t&&&',
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:6,
publishTime:3,
permalink:'blog/static/',
commentCount:0,
mainCommentCount:0,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}import types&type(x) is types.IntType # 判断是否int 类型&type(x) is types.StringType #是否string类型&.........&--------------------------------------------------------超级恶心的模式,不用记住types.StringTypeimport types&type(x) == types(1) # 判断是否int 类型&type(x) == type('a') #是否string类型python中如何判断一个变量的数据类型?
[问题点数:20分,结帖人zhenhaojia]
python中如何判断一个变量的数据类型?
[问题点数:20分,结帖人zhenhaojia]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2006年4月 其他开发语言大版内专家分月排行榜第三2004年12月 其他开发语言大版内专家分月排行榜第三
2006年4月 其他开发语言大版内专家分月排行榜第三2004年12月 其他开发语言大版内专家分月排行榜第三
2012年1月 其他开发语言大版内专家分月排行榜第二2011年5月 其他开发语言大版内专家分月排行榜第二2010年12月 其他开发语言大版内专家分月排行榜第二2009年2月 其他开发语言大版内专家分月排行榜第二2008年9月 其他开发语言大版内专家分月排行榜第二2008年8月 其他开发语言大版内专家分月排行榜第二2008年5月 其他开发语言大版内专家分月排行榜第二2007年11月 其他开发语言大版内专家分月排行榜第二
2011年4月 其他开发语言大版内专家分月排行榜第三2011年1月 其他开发语言大版内专家分月排行榜第三2009年6月 其他开发语言大版内专家分月排行榜第三2009年4月 其他开发语言大版内专家分月排行榜第三2009年1月 其他开发语言大版内专家分月排行榜第三2008年11月 其他开发语言大版内专家分月排行榜第三2008年7月 其他开发语言大版内专家分月排行榜第三2008年6月 其他开发语言大版内专家分月排行榜第三2006年9月 其他开发语言大版内专家分月排行榜第三
本帖子已过去太久远了,不再提供回复功能。

我要回帖

更多关于 python nonetype 判断 的文章

 

随机推荐