URN Logo
UNIX Resources » Linux » China Linux Forum » Python 编 程 » 19 » 一个奇怪的问题
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
一个奇怪的问题
一个奇怪的问题 - weirise [2004-04-21 10:59 | 1,944 byte(s)]
 
Re: 一个奇怪的问题 - weirise [2004-04-21 11:37 | 14 byte(s)]
 
Re: 一个奇怪的问题 - rings [2004-04-21 11:32 | 96 byte(s)]
 
Subject: 一个奇怪的问题
Author: weirise    Posted: 2004-04-21 10:59    Length: 1,944 byte(s)
[Original] [Print] [Top]
我在运行同一个程序时出现了两种不同的结果,比较迷惑:
第一个:
def main():
a='4561','1230ww',
b='12341','1231','121ww','11',
print type(a)
for aa in a:
print type(a)
for bb in b:
print type(bb)
if aa == bb:
print "aa is :%s" % aa
print "find ok"
return 1
else:
print "aa:%s bb:%s" %(aa,bb)
print "not found"
return 0
if __name__=="__main__":
main()
执行的结果:
<type 'tuple'>
<type 'tuple'>
<type 'str'>
aa:4561 bb:12341
<type 'str'>
aa:4561 bb:1231
<type 'str'>
aa:4561 bb:121ww
<type 'str'>
aa:4561 bb:11
<type 'tuple'>
<type 'str'>
aa:1230ww bb:12341
<type 'str'>
aa:1230ww bb:1231
<type 'str'>
aa:1230ww bb:121ww
<type 'str'>
aa:1230ww bb:11
not found
比较正常,但是在程序里调用时,去出现如下所示:

def dir_compare(dir_comparing,dir_compared,dir_count):
a=123,345
b=2,123,1234
for aa in a:
for bb in b:
if aa == bb:
print "find ok"
return 1
else:
print "aa:%s bb:%s" %(aa,bb)
print "not found"
执行的结果如下:
aa:1 bb:2
aa:1 bb:1
这里的aa并不是取值123,不知为何?请教!!!!
[Original] [Print] [Top]
Subject: Re: 一个奇怪的问题
Author: rings    Posted: 2004-04-21 11:32    Length: 96 byte(s)
[Original] [Print] [Top]
我执行你的第二个函数的结果是
aa:123 bb:2
find ok

是对的呀。
[Original] [Print] [Top]
Subject: Re: 一个奇怪的问题
Author: weirise    Posted: 2004-04-21 11:37    Length: 14 byte(s)
[Original] [Print] [Top]
我现在也纳闷那
[Original] [Print] [Top]
« Previous thread
探讨Plone
Python 编 程
19
Next thread »
元组与列表之间的转换问题
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 04:11:41, cost 0.035907983779907 ms.