In [2]:
#输入输出
name = input();
print(name);
#也可以输出提示语
name = input('please enter your name: ');
print('hello,', name);


zmw
zmw
please enter your name: zmw
hello, zmw

In [5]:
print('I\'m "OK"');
print('I\'m \"OK\"');


I'm "OK"
I'm "OK"

In [7]:
#选择排序
def selSort(L):
    for i in range(len(L)):
        num = i;
        val = L[i];
        for j in range(i+1,len(L)):
            if val > L[j]:
                num = j;
                val = L[j];
                temp = L[i];
                L[i] = val;
                L[num] = temp;
        print(L);
L = [1,3,5,7,2,4];
selSort(L);


[1, 3, 5, 7, 2, 4]
[1, 2, 5, 7, 3, 4]
[1, 2, 3, 7, 5, 4]
[1, 2, 3, 4, 7, 5]
[1, 2, 3, 4, 5, 7]
[1, 2, 3, 4, 5, 7]

In [11]:
intList = [1,2,5,5,5,2,3,3,9];
print(intList.count(5));#计数,看总共有多少个5
print(intList.index(3));#查询 list的第一个3的下标
print(intList.pop());# 从list中去除最后一个元素,并将该元素返回。
print(intList);
print(type(intList.append(9)));   #在 list 的最后增添一个新元素6, 无返回值
print(intList);
print(intList.remove(2))#移除第一个2,无返回值
print(intList);
print(intList.insert(0,10));#在下标为0的位置插入10
print(intList);


3
6
9
[1, 2, 5, 5, 5, 2, 3, 3]
<class 'NoneType'>
[1, 2, 5, 5, 5, 2, 3, 3, 9]
None
[1, 5, 5, 5, 2, 3, 3, 9]
None

In [ ]: