Chinaunix首页 | 论坛 | 博客
  • 博客访问: 388925
  • 博文数量: 199
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1530
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 08:43
文章分类

全部博文(199)

文章存档

2015年(101)

2014年(97)

2011年(1)

发布时间:2015-05-26 12:24:32

英文说明:Convert a value to a Boolean, using the standard truth testing procedure. If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.New in versio.........【阅读全文】

阅读(1188) | 评论(0) | 转发(0)

发布时间:2015-05-26 12:18:55

bin(x)英文说明:Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.New in version 2.6.中文说明:将整数x转换为二进制字符串,如果x不为Python中int类型,x必须包含方法_.........【阅读全文】

阅读(966) | 评论(0) | 转发(0)

发布时间:2015-05-26 12:11:10

说明:如果iterable的任何元素不为0、''、False,all(iterable)返回True。如果iterable为空,返回False。函数等价于:注意比较该函数与all()函数的区别,any是任意,而all是全部。建议比较学习两者的区别与联系。可以参考《python函数每日一讲 - all()》def any(iterable):   for element in iterable: .........【阅读全文】

阅读(914) | 评论(0) | 转发(0)

发布时间:2015-05-26 11:03:16

说明:如果iterable的所有元素不为0、''、False或者iterable为空,all(iterable)返回True,否则返回False参数iterable:可迭代对象>>> all(['a', 'b', 'c', 'd'])  #列表list,元素都不为空或0True>>> all(['a', 'b', '', 'd'])  #列表list,存在一个为空的元素False>>> all([0, 1,2, 3])  #列表list.........【阅读全文】

阅读(914) | 评论(0) | 转发(0)

发布时间:2015-05-26 10:47:40

先看官方英文文档解释abs(x)Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.详解:返回绝对值参数可以是:负数、正数、浮点数或者长整形实例:abs(-1.2) #返回 1.2abs(1.2) .........【阅读全文】

阅读(822) | 评论(0) | 转发(0)

发布时间:2015-04-23 23:17:02

CPU信息/proc/cpuinfo文件包含了你的系统处理器单元的信息。例如,这里就是python版的linux命令cat /proc/cpuinfo所做的事:#! /usr/bin/env python""" print out the /proc/cpuinfo    file"""from __future__ import print_functionwith open('/proc/cpuinfo') as f:    for line in f:&nbs.........【阅读全文】

阅读(1229) | 评论(0) | 转发(0)

发布时间:2015-03-11 11:43:24

1.failed to set __main__.__loader__       配置好Python环境,运行1-100和.py实例就出现这个异常,原来是文件名包含非英文字符,将名字改为英文就没问题了......【阅读全文】

阅读(1071) | 评论(1) | 转发(0)

发布时间:2015-03-05 10:24:16

Python中的strip用于去除字符串的首尾字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符。这三个函数都可传入一个参数,指定要去除的首尾字符。需要注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如:.........【阅读全文】

阅读(888) | 评论(1) | 转发(0)

发布时间:2015-01-17 16:35:19

#找出0~100之间的所有素数from math import sqrtN = 100#基本的方法result1 = []for num in range(2, N):    f = True    for snu in range(2, int(sqrt(num))+1):        if num % snu == 0:            f = False      .........【阅读全文】

阅读(846) | 评论(0) | 转发(0)

发布时间:2015-01-17 16:09:42

#利用python作为科学计算器。熟悉Python中的常用运算符,并分别求出表达式12*34+78-132/6、(12*(34+78)-132)/6、(86/40)**5的值。并利用math模块进行数学计算,分别求出145/23的余数,0.5的sin和cos值(注意sin和cos中参数是弧度制表示)x = 12*34+78-132/6y = (12*(34+78)-132)/6z = (86/40)**5print ('12*34+78-132/6.........【阅读全文】

阅读(1112) | 评论(1) | 转发(0)

发布时间:2015-01-17 15:16:34

判断闰年条件, 满足年份模400为0, 或者模4为0但模100不为0. import timethisyear = time.localtime()[0]if thisyear % 400 == 0 or thisyear % 4 ==0 and thisyear % 100 != 0:print ('this year %s is a leap year' % thisyear)else:print ('this year %s is not a leap year' % thisyear)this year 2015 is .........【阅读全文】

阅读(950) | 评论(0) | 转发(0)

发布时间:2014-11-03 12:29:46

# -*- coding: UTF-8 -*-'''【程序99】题目:有两个磁盘文件A和B,各存放一行字母,要求把这两个文件中的信息合并(按字母顺序排列),  输出到一个新文件C中.1.程序分析:2.程序源代码:'''if __name__ == '__main__':    import string    fp = open('JCP099.py')    a = fp..........【阅读全文】

阅读(1471) | 评论(0) | 转发(0)

发布时间:2014-11-03 12:20:18

# -*- coding: UTF-8 -*-'''【程序98】题目:从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存。   输入的字符串以!结束。 1.程序分析:2.程序源代码:'''if __name__ == '__main__':    fp = open('test.txt','w')    string = input('.........【阅读全文】

阅读(1636) | 评论(0) | 转发(0)

发布时间:2014-11-03 11:16:04

# -*- coding: UTF-8 -*-'''【程序97】题目:从键盘输入一些字符,逐个把它们送到磁盘上去,直到输入一个#为止。1.程序分析:     2.程序源代码:'''if __name__ == '__main__':    from sys import stdout    filename = input('input a file name:\n')    fp = open(filena.........【阅读全文】

阅读(1329) | 评论(0) | 转发(0)

发布时间:2014-11-03 11:11:17

# -*- coding: UTF-8 -*-'''【程序96】题目:计算字符串中子串出现的次数1.程序分析:2.程序源代码:'''if __name__ == '__main__':    str1 = input('input a string:\n')    str2 = input('input a sub string:\n')    ncount = str1.count(str2)    print (ncount)&.........【阅读全文】

阅读(1298) | 评论(0) | 转发(0)

发布时间:2014-11-03 11:03:57

# -*- coding: UTF-8 -*-'''【程序94】题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。(版主初学时编的)1.程序分析:2.程序源代码:'''if __name__ == '__main__':    import time    import random        play_it = input('do you want to play it.(.........【阅读全文】

阅读(1084) | 评论(0) | 转发(0)

发布时间:2014-11-01 22:06:02

# -*- coding: UTF-8 -*-'''【程序93】题目:时间函数举例31.程序分析:2.程序源代码:'''if __name__ == '__main__':    import time    start = time.clock()    for i in range(10000):        print (i)    end = time.clock()   .........【阅读全文】

阅读(943) | 评论(0) | 转发(0)

发布时间:2014-11-01 21:47:13

# -*- coding: UTF-8 -*-'''【程序92】题目:时间函数举例21.程序分析:           2.程序源代码:'''if __name__ == '__main__':    import time    start = time.time()    for i in range(3000):        print (i)    end = time.t.........【阅读全文】

阅读(910) | 评论(0) | 转发(0)

发布时间:2014-11-01 21:28:01

# -*- coding: UTF-8 -*-''' 【程序91】题目:时间函数举例11.程序分析:2.程序源代码:'''if __name__ == '__main__':    import time    print (time.ctime(time.time()))    print (time.asctime(time.localtime(time.time())))    print (time.asctime(time.g.........【阅读全文】

阅读(1076) | 评论(0) | 转发(0)

发布时间:2014-10-31 17:17:48

# -*- coding: UTF-8 -*-'''【程序90】题目:专升本一题,读结果。1.程序分析:2.程序源代码:'''if __name__ == '__main__':    M = 5    a = [1,2,3,4,5]    i = 0    j = M - 1    while i < M:        a[i],a[j] = a[j],a[i]&nbs.........【阅读全文】

阅读(1017) | 评论(0) | 转发(0)
给主人留下些什么吧!~~
留言热议
请登录后留言。

登录 注册