免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5240 | 回复: 19
打印 上一主题 下一主题

初学者感言 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-05 15:04 |只看该作者 |倒序浏览
我刚刚自学python,一头雾水,一个比较完整的例子看不懂啊,尤其是继承来继承去的,方法调用也挺乱的,那为大侠传授点入门经验啊啊??
读python源码应该怎么解析更容易理解a  ??
别笑我*^-^*

论坛徽章:
4
CU大牛徽章
日期:2013-03-13 15:29:07CU大牛徽章
日期:2013-03-13 15:29:49CU大牛徽章
日期:2013-03-13 15:30:192015亚冠之广州恒大
日期:2015-07-22 17:20:15
2 [报告]
发表于 2007-04-05 15:06 |只看该作者
没什么特别的习惯就好 如果你以前用过其他的面向对象的语言
你会发现 很简单的

从基础看起,不懂的 google 或者 查资料

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2007-04-05 15:18 |只看该作者
这是正常的,先看书,别急躁。
连一本书都静不下心来看,还学什么语言啊。

论坛徽章:
0
4 [报告]
发表于 2007-04-05 15:33 |只看该作者
呵呵,谢了
我想起了一句经典台词"是男人就就该挺过去!!"
我一定回努力的,以后还希望大家多多帮忙啊!!!
谢谢大家的鼓励!!!

论坛徽章:
0
5 [报告]
发表于 2007-04-05 16:11 |只看该作者

  1. # 你的爸爸媽媽
  2. class 家長:
  3.       
  4.         def __init__(self):
  5.                 self.媽媽 = 'Ling'   
  6.                 self.爸爸 = 'Po'     

  7.         def get_媽媽(self):         
  8.                 return self.媽媽      

  9.         def get_爸爸(self):
  10.                 return self.爸爸
  11.         
  12.         def 肚子餓(self):
  13.                 print '肚子餓了, 一起吃飯'
  14.        
  15. # 你爸爸媽媽生你,所以你也继承了他們的DNA
  16. class 兒子(家長):

  17.         def __init__(self, 自己):
  18.                 家長.__init__(self)
  19.                 self.自己 = 自己

  20.         def get_自己(self)
  21.                 return self.自己

  22. if __name__=='__main__':
  23.         # 生了一個兒子
  24.         我 = 兒子(自己='Kyle')
  25.    
  26.         print '我媽媽叫 %s ' % 我.get_媽媽()
  27.         print '我爸爸叫 %s ' % 我.get_爸爸()
  28.         我.肚子餓()
  29.         print '他們幫我取了名叫 %s ' % 我.get_自己()       

  30. OUTPUT:
  31. 我媽媽叫 Ling
  32. 我爸爸叫 Po
  33. 肚子餓了, 一起吃飯
  34. 他們幫我取了名叫 Kyle
复制代码

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2007-04-05 16:38 |只看该作者
楼上你这个类设计得可不怎么样啊。
家长的爸爸也叫 Po?
显然是不对的。
而且
我 = 儿子(自己='Kyle')
这种写法也不合理。

论坛徽章:
0
7 [报告]
发表于 2007-04-05 17:04 |只看该作者
我也是刚接触了一周时间,觉得python真的是一门可以减少敲键盘的语言。
我想专向于WEB Program 方面的,请问版主姐姐,有什么好的入门方法吗?
本人有PHP基础的。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2007-04-05 17:10 |只看该作者
给一个我设计的:
  1. import random

  2. class Person:
  3.     def __init__(self, gender, name=None ):
  4.         self.gender = gender
  5.         self.name = name
  6.         self.father = None
  7.         self.mother = None
  8.         self.bloodline = None

  9.     def give_birth(self, spouse):
  10.         if( self.gender == spouse.gender ):
  11.             return None

  12.         print "%s and %s give birth a baby..." % ( self.name, spouse.name )
  13.         gender = random.choice( ['male', 'female'] )
  14.         baby = Person(gender)

  15.         if gender == 'male':
  16.             print 'It is a boy.'
  17.         else:
  18.             print 'It is a girl.'

  19.         if self.gender == 'male':
  20.             baby.father = self
  21.             baby.mother = spouse
  22.         else:
  23.             baby.father = spouse
  24.             baby.mother = self

  25.         baby.bloodline = baby.father.bloodline
  26.         print
  27.         return baby

  28.     def naming(self, name):
  29.         self.name = name

  30.     def hello_world(self):
  31.         print 'My name is', self.name
  32.         if self.father != None:
  33.             print 'My father is', self.father.name
  34.         if self.mother != None:
  35.             print 'My mother is', self.mother.name
  36.         print

  37. if __name__ == '__main__':
  38.     alpha = Person( 'male', 'Po' )
  39.     beta = Person( 'female', 'Ling' )

  40.     alpha.hello_world()
  41.     beta.hello_world()

  42.     gamma = alpha.give_birth( beta )
  43.     gamma.naming('Kyle')

  44.     gamma.hello_world()
复制代码

输出:
  1. D:\MoChou>ttt
  2. My name is Po

  3. My name is Ling

  4. Po and Ling give birth a baby...
  5. It is a boy.

  6. My name is Kyle
  7. My father is Po
  8. My mother is Ling
复制代码

[ 本帖最后由 flw 于 2007-4-5 17:13 编辑 ]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
9 [报告]
发表于 2007-04-05 17:12 |只看该作者
有许多被忽略的细节:
1,不是任何时候都可以生孩子的……得看是不是安全期
2,生下来的孩子得长大了才能说话,一生下来就会说话的我知道的只有哪吒……
其它,等等……

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
10 [报告]
发表于 2007-04-05 17:14 |只看该作者
原帖由 smilingdolphin 于 2007-4-5 17:04 发表
有什么好的入门方法吗?

读书
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP