ChinaUnix.net
相关文章推荐:

python24 string 左对齐

请教,如何在CLP中使string对齐?就是去掉string右边的空格。

by huaimie - AS400 - 2006-03-15 17:19:28 阅读(1888) 回复(9)

相关讨论

最近总是在不同的机器间切换,而且有时会把windows上的python拷贝到linux上编辑然后执行,总是遇到很多的对齐问题 请问大家这种情况应该怎么办啊,我现在把我的vim设置了 set tabstop=4 set shiftwidth=4 set expandtab 但还是有这个问题,应该怎样解决?多谢,最近被这个问题很是烦恼

by tianqio - Python - 2008-10-12 16:38:01 阅读(7107) 回复(10)

该结构大致如下: struct TestStruct { int data1; char data2; char data3; }; 对应的python代码: import struct s = struct.unpack("icc", buf) #buf是从网络接收的字节流 结果却报“Unpack str size does not match format”错。 很明显是C++ struct产生的size和python解码所需的不同。于是检查C++的struct size: printf ("size=%d\n", sizeof(TestStruct)); 结果得8。 而 struct.calcsize("icc") 结果却是6。 仔...

by blackjimmy - Python文档中心 - 2009-08-21 10:58:50 阅读(3279) 回复(0)

http://codeftw.blogspot.com/2007/04/reverse-string-in-python.html While reading " Some Call it Concatenation " (which is funny, btw), some commenters are getting crazy and started to write in reverse. You know, in esrever. It's easy to write it, just use your left arrow key, but reading it is a pain. So after reading one of them and met another few, I thought, "Let's reverse it using a program. P...

by dongtao - Linux文档专区 - 2008-04-01 22:57:03 阅读(997) 回复(0)

python有各种各样的string操作函数。在历史上string类在python中经历了一段轮回的历史。在最开始的时候,python有一个专门的string的module,要使用string的方法要先import,但后来由于众多的python使用者的建议,从python2.0开始,string方法改为用S.method()的形式调用,只要S是一个字符串对象就可以这样使用,而不用import。同时为了保持向后兼容,现在的python中仍然保留了一个string的module,其中定义的方法与S.method()是...

by uranusllj - Python文档中心 - 2009-07-30 10:02:50 阅读(2216) 回复(0)

对于一个字符串,最基本的操作就是连接、截取。在python中,’+‘是字符串连接符,截取则要用到python一个强 大功能slice,也就所谓的切片,很形象。在’+‘连接字符串的时候,需要注意一点,“+”不能用来连接一个字符串和一个数字,因为“+”也同时是数字 在加法运算符,如果你写出4+'times',那么电脑是应该把4变成字符串呢,还是应该把’times‘变成数字呢?这就成问题了,所以这是不允许的。 同时就跟乘法是加法的一种形式一样...

by marlboro027 - Python文档中心 - 2007-03-30 15:25:28 阅读(1167) 回复(0)

对于一个字符串,最基本的操作就是连接、截取。在python中,’+‘是字符串连接符,截取则要用到python一个强大功能slice,也就所谓的切片,很形象。在’+‘连接字符串的时候,需要注意一点,“+”不能用来连接一个字符串和一个数字,因为“+”也同时是数字在加法运算符,如果你写出4+'times',那么电脑是应该把4变成字符串呢,还是应该把’times‘变成数字呢?这就成问题了,所以这是不允许的。同时就跟乘法是加法的一种形式一样...

by newsim - Python文档中心 - 2006-02-22 15:27:43 阅读(1219) 回复(0)

he first article in this series covered important changes to the core language and its type system. This article focuses on how python 3.0 treats the basic data types: numbers, text, and binary data. PEP 237: Unifying Long Integers and Integers python 2.x has two integral types: int and long. The int type is limited to the machine's "native" word size (32 or 64 bit in modern machines). Operat...

by cobrawgl - Python文档中心 - 2009-04-11 07:58:37 阅读(1960) 回复(0)

python有各种各样的string操作函数。在历史上string类在python中经历了一段轮回的历史。在最开始的时候,python有一个专 门的string的module,要使用string的方法要先import,但后来由于众多的python使用者的建议,从python2.0开始, string方法改为用S.method()的形式调用,只要S是一个字符串对象就可以这样使用,而不用import。同时为了保持向后兼容,现在的 python中仍然保留了一个string的module,其中定义的方法与S.method...

by marlboro027 - Python文档中心 - 2007-04-01 15:28:00 阅读(1078) 回复(0)

python中也有类似于c中的printf()的格式输出标记。在python中格式化输出字符串使用的是%运算符,通用的形式为 格式标记字符串 % 要输出的值组其中,边部分的”格式标记字符串“可以完全和c中的一致。右边的'值组'如果有两个及以上的值则需要用小括号括起来,中间用短号隔开。重点来看边的部分。边部分的最简单形式为: %cdoe其中的code有多种,不过由于在python中,所有东西都可以转换成string类型,因此,如果没有什么特殊...

by marlboro027 - Python文档中心 - 2007-04-01 15:27:19 阅读(1192) 回复(0)

string and Unicode objects have one unique built-in operation: the % operator (modulo). This is also known as the string formatting or interpolation[改写] operator. Given format % values (where format is a string or Unicode object), % conversion specifications in format are replaced with zero or more elements of values. The effect is similar to the using sprintf() in the C language. If format is ...

by linxh - Python文档中心 - 2006-08-02 10:57:34 阅读(1475) 回复(0)