python每次处理一个字符的三种方法 a_string = "abccdea" print 'the first' for c in a_string: print ord(c)+1 print "the second" result = [ord(c)+1 for c in a_string] print result print "the thrid" def do_something(c): return ord(c)+1 result…
""" Python3.4[文本]之每次处理一个字符 """ test_str = "my name is bixiaopeng" for x in range( 0, len(test_str)-1): print ("## 通过索引遍历字符串: " + test_str[x]) for x in test_str: print ("## 直接遍历字符串: " + x) thelist…
在Python中字符就是长度为1的字符串,所以可以循环遍历一个字符串,依次访问每一个字符,得到你想要的处理前提: 一个列表是个好主意,就像这样:thelist = list(thestring) 当然,完全可以不用列表,对于喜欢循环遍历的人,他们有足够的理由这么做,因为并没有创建列表的过程: for c in thestring: do_something_with(c) 知道列表推导的人,肯定不屑于上面的写法,因为下面的代码是他们常引以为豪的: results = [do_something_…
本文首发于微信公众号:程序员乔戈里 public class testT { public static void main(String [] args){ String A = "hi你是乔戈里"; System.out.println(A.length()); } } 以上结果输出为7. 小萌边说边在IDEA中的win环境下选中String.length()函数,使用ctrl+B快捷键进入到String.length()的定义. /** * Returns the length…