ChinaUnix.net
相关文章推荐:

python 随机字符串

[color="#0000f0"] 随机整数: >>> import random >>> random.randint(0,99) 21 [color="#000080"]随机选取0到100间的偶数: >>> import random >>> random.randrange(0, 101, 2) 42 [color="#0000f0"]随机浮点数: >>> import random >>> random.random() 0.85415370477785668 >>> random.uniform(1, 10) 5.4221167969800881 [color="#0000f0"]随机字符: >>> import random >>> random.choice('abcdefg&#%^*f') 'd'...

by bj2008_0201 - Python文档中心 - 2008-09-11 10:27:44 阅读(1917) 回复(0)

相关讨论

随机整数: >>> import random >>> random.randint(0,99) 21 随机选取0到100间的偶数: >>> import random >>> random.randrange(0, 101, 2) 42 随机浮点数: >>> import random >>> random.random() 0.85415370477785668 >>> random.uniform(1, 10) 5.4221167969800881 随机字符: >>> import random >>> random.choice('abcdefg&#%^*f') 'd' 多个字符中选取特定数量的字符: >>> import random random.sample('...

by mystérieux - Python文档中心 - 2007-09-03 19:29:30 阅读(3091) 回复(0)

随机整数: >>> import random >>> random.randint(0,99) 21 随机选取0到100间的偶数: >>> import random >>> random.randrange(0, 101, 2) 42 随机浮点数: >>> import random >>> random.random() 0.85415370477785668 >>> random.uniform(1, 10) 5.4221167969800881 随机字符: >>> import random >>> random.choice('abcdefg&#%^*f') 'd' 多个字符中选取特定数量的字符: >>> import random random.sample('abcd...

by ywh214 - Python文档中心 - 2009-12-21 16:11:53 阅读(2366) 回复(0)

随机整数: >>> import random >>> random.randint(0,99) 21 随机选取0到100间的偶数: >>> import random >>> random.randrange(0, 101, 2) 42 随机浮点数: >>> import random >>> random.random() 0.85415370477785668 >>> random.uniform(1, 10) 5.4221167969800881 随机字符: >>> import random >>> random.choice('abcdefg&#%^*f') 'd' 多个字符中选取特定数量的字符: >>> import random random.sample('abcdefghij',3) ...

by alexnetwork - Python文档中心 - 2009-03-11 21:56:01 阅读(1168) 回复(0)

我有一段字符串如“d['a']={}"我想让他当成python命令来执行我该怎么做 谢谢

我该怎么做字符串

by tanbaolin1218 - Python - 2011-02-24 14:33:40 阅读(2511) 回复(2)

str[0:5] 截取第一位到第四位的字符 str[:] 截取字符串的全部字符 str[4:] 截取第五个字符到结尾 str[:-3] 截取从头开始到倒数第三个字符之前 str[2] 截取第三个字符 str[::-1] 创造一个与原字符串顺序相反的字符串

by c_u_c_u - Python - 2010-11-02 17:40:28 阅读(2359) 回复(1)

def mytrim(zstr) ystr=zstr.lstrip() ystr=ystr.rstrip() ystr=ystr.strip() return ystr 在编程中,几乎90% 以上的代码都是关于整数或字符串操作,所以与整数一样,python字符串实现也使用了许多拿优化技术,使得字符串的性能达到极致。与 C++ 标准库(STL)中的 std::string 不同,python 字符串集合了许多字符串相关的算法,以方法成员的方式提供接口,使用起来非常方便。 字符串方法大约有几十个,这些方法可以分为如下几类...

by hkebao - Python文档中心 - 2009-11-03 09:39:47 阅读(2568) 回复(0)

#python字符串操作 '''1.复制字符串''' #strcpy(sStr1,sStr2) sStr1 = 'strcpy' sStr2 = sStr1 sStr1 = 'strcpy2' print sStr2 '''2.连接字符串''' #strcat(sStr1,sStr2) sStr1 = 'strcat' sStr2 = 'append' sStr1 += sStr2 print sStr1 '''3.查找字符''' #strchr(sStr1,sStr2) sStr1 = 'strchr' sStr2 = 'r' nPos = sStr1.index(sStr2) print nPos '''4.比较字符串''' #strcmp(sStr1,sStr2) sStr1 = 'strchr' sStr2 = 'strch' pr...

by yangguosdxl - Python文档中心 - 2009-04-17 14:19:01 阅读(2082) 回复(0)

#python字符串操作 '''1.复制字符串''' #strcpy(sStr1,sStr2) sStr1 = 'strcpy' sStr2 = sStr1 sStr1 = 'strcpy2' print sStr2 '''2.连接字符串''' #strcat(sStr1,sStr2) sStr1 = 'strcat' sStr2 = 'append' sStr1 += sStr2 print sStr1 '''3.查找字符''' #strchr(sStr1,sStr2) sStr1 = 'strchr' sStr2 = 'r' nPos = sStr1.index(sStr2) print nPos '''4.比较字符串''' #strcmp(sStr1,sStr2) sStr1 = 'strchr' sStr2 = 'strch' pr...

by jcodeer - Python文档中心 - 2007-09-15 02:34:31 阅读(1193) 回复(0)

1 字符串概述 字符串(string)是python内置数据类型的一种,它是一个有序的字符的集合,用于存储和表示基本的文本信息。从功能的角度来看,字符串可以被用于实现任何可以作为文本编码的数据:字母、数字和其他特殊符号的集合,载入读入内存中的文本文件的内容等。 字符串是最常见的数据类型的一种,在任何编程语言都不可或缺的,而且都占有非常重要的地位。为了让大家能从感性上认识到字符串数据的作用,不妨来看看这个简单的例...

by pascal4123 - Python文档中心 - 2007-07-31 11:00:25 阅读(1385) 回复(0)

转自: commath python中的random模块用于生成随机数。下面介绍一下random模块中最常用的几个函数。 random.random random.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 random.uniform   random.uniform的函数原型为:random.uniform(a, b),用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限。如果a > b,则生成的随机数n: a <= n <= b。如果 a

by wyd1990 - Python - 2010-11-12 17:59:39 阅读(9777) 回复(1)