浅尝python语法,挺有意思的与c#语法做了对比 原创 create by lee
时间:2010-11-04 来源:陈力
////////////////////////////////////////////////////////////////
>>> # 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
//与c#做对照
{
string[] strArrary = { "a","b","c","d","e","f"};
for (int i = 0; i < strArrary.Length; i++)
{
Console.WriteLine("{0},{1}",i,strArrary[i]);
}
}
相关阅读 更多 +