浅尝python语法,挺有意思的。
////////////////////////////////////////////////////////////////
>>> # Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
... print(x, len(x))
...
cat 3
window 6
defenestrate 12
////////////////////////////////////////////////////////////////
>>> for x in a[:]: # make a slice copy of the entire list
... if len(x) > 6: a.insert(0, x)
...
>>> a
['defenestrate', 'cat', 'window', 'defenestrate']
>>> for i in range(5):
... print(i)
...
0
1
2
3
4
代码
////////////////////////////////////////////////////////////////
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print(i, a[i])
...
0 Mary
1 had
2 a
3 little
4 lamb
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print(i, a[i])
...
0 Mary
1 had
2 a
3 little
4 lamb
//与c#做对照
代码
static void Main(string[] args)
{
string[] strArrary = { "a","b","c","d","e","f"};
for (int i = 0; i < strArrary.Length; i++)
{
Console.WriteLine("{0},{1}",i,strArrary[i]);
}
}
{
string[] strArrary = { "a","b","c","d","e","f"};
for (int i = 0; i < strArrary.Length; i++)
{
Console.WriteLine("{0},{1}",i,strArrary[i]);
}
}