1: ‘‘‘2: 数组 有list和tuple之分3: ‘‘‘4:5: classmates=[‘a‘,‘b‘,‘c‘,‘d‘]6: print(classmates)7: length=len(classmates)8: print(length)#49: print(classmates[0]+classmates[1]) # ab10: #print(classmates[5])#IndexError: list index out of range11: print(classmates[-1])#!最后一个元素的索引是-112: classmates.append(88)#在最后加个元素8813: print(classmates)14: classmates.insert(2,45)15: ‘‘‘16: 向第二个位置增加一个4517: ‘‘‘18: print(classmates)19: classmates.pop(-2)20: ‘‘‘21: 删除倒数第二个元素22: ‘‘‘23: print(classmates)24: a=[[1,2,3],[4,5,6],[7,8,9]]25: print(a)26:27:28: ‘‘‘29: tuple 不能变,一旦定义不能改。一个tuple 被定义后元素就必须定下来。30: ‘‘‘31: classmates=(‘a‘,‘b‘,‘c‘)32: p=[‘asp‘,‘php‘]33: s=[‘python‘,‘java‘,p,‘scheme‘]34: print(s[2][1])35: a=()36: print(a)37: #定义只有一个元素的tuple的时候必须在定义后面加一个“,”38: a=(1,)39: print(a)40: ‘‘‘41: 输出为(1,)42: ‘‘‘43:44: a=(1)45: print(a)#输出为146: #但是这样可以变:47: L=(‘a‘,‘b‘,[1,2])48: print(L)49: L[2].append(54)50: print(L)51: #但这样变的只是L中的tuple。52: L = [53: [‘Apple‘, ‘Google‘, ‘Microsoft‘],54: [‘Java‘, ‘Python‘, ‘Ruby‘, ‘PHP‘],55: [‘Adam‘, ‘Bart‘, ‘Lisa‘]56: ]57: print(L[0][0],L[1][1],L[2][2]).csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
时间: 2024-11-06 09:58:14