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) 编辑