2011年12月9日
摘要: typedef的用法typedef的作用是真正意义上地定义一种别名,而不是一种简单的宏替换。typedef 与 #define的区别:案例一:通常讲,typedef要比#define要好,特别是在有指针的场合。请看例子:typedef char *pStr1;#define pStr2 char *;pStr1 s1, s2;pStr2 s3, s4;在上述的变量定义中,s1、s2、s3都被定义为char *,而s4则定义成了char,不是我们所预期的指针变量,根本原因就在于#define只是简单的字符串替换而typedef则是为一个类型起新名字。注意语句char* pa,pb; 其中pa定义 阅读全文
posted @ 2011-12-09 16:25 bovine 阅读(265) 评论(0) 推荐(0) 编辑
  2011年11月27日
摘要: Determine if you win or loose a hazard game.Somebody suggests the following game. You pay 1 unit of money and areallowed to throw four dice. If the sum of the eyes on the dice is less than 9,you win 1... 阅读全文
posted @ 2011-11-27 21:27 bovine 阅读(767) 评论(0) 推荐(0) 编辑
  2011年11月26日
摘要: 编写简单脚本: you draw n random uniformly distributed numbers, where n is given on the command line, and compute the average of these numbers. the lesson learned from this little prctice can be concluded as... 阅读全文
posted @ 2011-11-26 21:13 bovine 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 什么是高斯消元法?请见维基百科的定义MATLAB实现:function x = gauss(a,b)n = length(b);for i = 1 : n-1 for j = (i+1) : n if a(i,i)~=0 lam = a(j,i)/a(i,i); a(j,(i+1):n) = a(j,(i+1):n) - lam*a(i,(i+1):n); b(j) = b(j) -lam*b(i); end endendfor i = n:-1:1 b(i) = (b(i) - sum(a(i,(i+1)... 阅读全文
posted @ 2011-11-26 18:07 bovine 阅读(5550) 评论(0) 推荐(0) 编辑
摘要: 作者:winterTTr (转载请注明) 我想,这个标题或许是很多初学者的问题。尤其是像我这样的对C/C++比较熟悉,刚刚进入python殿堂的朋友们 。C/C++的函数参数的传递方式根深蒂固的影响这我们的思维--引用?传值?究竟是那种呢。 呵呵,语言的特性决定了是使用的方法,那么,现在我们来探究一下python的函数参数传递方式。 在开始之前,我们有必要分清一下python的一些基础概念... 阅读全文
posted @ 2011-11-26 16:28 bovine 阅读(3449) 评论(2) 推荐(2) 编辑
  2011年11月25日
摘要: 关于Python随机数import random,发现这里面有很多randomize的method,这里不再一一赘述,可以通过帮助文档自习看,包括choice,shuffle都是集成度很高的randomize方法于是尝试了一个这样一个task,输入字符串长度,输出一个随机产生的字符串。巩固了一下异常的相关处理方法。import randomdef getstr(n): temp = [] while len(temp) < n: temp.append(chr(97+random.randint(0,25))) return ''.join(temp) ... 阅读全文
posted @ 2011-11-25 16:20 bovine 阅读(302) 评论(0) 推荐(0) 编辑
摘要: python也有逻辑上的分行键\。类似MATLAB里面的…input and output#!/usr/bin/python# Filename: using_file.pypoem = '''\Programming is funWhen the work is doneif you wanna make your work also fun:use Python!'''f = file('poem.txt', 'w') # open for 'w'ritingf.write(poem) # wr 阅读全文
posted @ 2011-11-25 07:06 bovine 阅读(336) 评论(0) 推荐(0) 编辑
摘要: 学习语言最好的办法就是实践,这句话一点都不假!今天完成了一个Python的小脚本,但是其中却遇到了一些意想不到的困难,最终通过上网搜索资料终于将这些问题解决了,对于我这个连Python都还不是太懂的菜鸟来说,真的很不容易啊!学到了什么?python中r的用法,r'str'表示raw string,既忽略转义字符。因为和windows不一样,python中认为\就是转义字符escape sequences的标志。python中提取系统时间,以及将其转化成字符串的方法。time.strftime()。将list转化成str的方法,s.join(list),其中s是list不同元素转 阅读全文
posted @ 2011-11-25 05:35 bovine 阅读(1865) 评论(0) 推荐(0) 编辑
摘要: 交换元素python的交换元素的方法非常简单,一般的编程语言中需要使用temporary variables,但是python中不需要>>> a = 1>>> b =2>>> c =3>>> a,b,c = c ,b,a>>> a3>>> b2>>> c1>>>construct a dictionary without excessive quoting>>> def makedic(**dic): return dic>&g 阅读全文
posted @ 2011-11-25 02:58 bovine 阅读(553) 评论(0) 推荐(0) 编辑
  2011年11月23日
摘要: IDLE编辑器快捷键自动代码补全:感觉好像IDLE里面其实是有这个功能的,不过有时候需要停顿一段时间太会有反应,翻看IDLE的快捷键,发现show completion的快捷键是ctrl+space,这和电脑里面输入法的切换冲突了,于是需要修改。修改的方法是:打开Options→configure IDLE→keys,找到force completion什么的来着进行快捷键修改,我修改后使用的快捷键是alt+v。其他一些比较常用的快捷键有:加缩进Ctrl+]减缩进Ctrl+[加注释Alt+3去注释Alt+4上一条命令Alt+p下一条命令Alt+nEnter鼠标选中后进行复制 阅读全文
posted @ 2011-11-23 14:21 bovine 阅读(7272) 评论(0) 推荐(0) 编辑