From c03b58046164b9d570a5d4110086c10ca13e6df9 Mon Sep 17 00:00:00 2001 From: JamesonHuang <462430725@qq.com> Date: Sat, 20 Jun 2015 15:18:34 +0800 Subject: [PATCH] test python strcat & foreach --- 2_0.python_test/foreach_test.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2_0.python_test/foreach_test.py diff --git a/2_0.python_test/foreach_test.py b/2_0.python_test/foreach_test.py new file mode 100644 index 0000000..f7e573b --- /dev/null +++ b/2_0.python_test/foreach_test.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# coding=utf-8 + +#遍历字符串每个字符 +word = 'helloworld!' +str = "strcat method4: " +for letter in word: + print "strcat method1: " + letter + print "strcat method2: ", letter + print "strcat method3: %s" %(letter) + #print str.join(letter) #fail + +#遍历数组元素 +words = ['hello', 'world'] +for word in words: + print "word:",word + +#for(int i = 0; i < 10; i += 2) +for num in range(0, 10, 2): + print num + +#index +for index in range(len(words)): + print words[index] +