| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1554 人关注过本帖
标题:请教duck type的详细信息
只看楼主 加入收藏
Yimmm
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-20
收藏
 问题点数:0 回复次数:1 
请教duck type的详细信息
我是学C#的,老师突然问道关于Python的一片外文中的duck type结果半天没有答上来。忘大神不吝赐教
搜索更多相关主题的帖子: 外文 问道 详细信息 
2012-03-20 17:55
为Jay沉沦
Rank: 2
来 自:四川成都西南交大
等 级:论坛游民
帖 子:40
专家分:25
注 册:2009-3-22
收藏
得分:0 
Duck typing

也许不翻译是最容易理解的了

definition: duck typing is a humorous way of describing the type non-checking system. initially coined by Dave Thomas in the Ruby community, its premise is that (referring to a value) "if it walks like a duck, and talks like a duck, then it is a duck."

 

Even though Boo is a statically typed language, Duck Typing is a way to fake being a dynamic language. Duck typing allows variables to be recognized at runtime, instead of compile time. Though this can add a sense of simplicity, it does remove a large security barrier.

e.g.

d as duck

d = 5 // 现在d是一个整型

print d

d += 100 // 能够做任何整型允许的操作

d = "hello" // 现在d变成了字符串类型了

print d

d = d.ToUpper() // 可以执行任何字符串操作了

print d
希望对你有用

无与伦比,为杰沉沦!
2012-04-12 20:59
快速回复:请教duck type的详细信息
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014998 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved