天天看點

Python練習-- list and tuple

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

classmates = ['Michael','Bob','Tracy']
print('classmates is:',classmates)
print('len is',len(classmates))
print('classmates[0] is',classmates[])
print('classmates[-1] is',classmates[-])

classmates.append('Adam')
print('classmates is:',classmates)
classmates.insert(,'Jack')
print('classmates is:',classmates)

print('pop:',classmates.pop())
print('classmates is:',classmates)

print('pop:',classmates.pop())
print('classmates is:',classmates)


classmates[] = 'Sarah'
print('classmates is:',classmates)


L = [
    ['Apple', 'Google', 'Microsoft'],
    ['Java', 'Python', 'Ruby', 'PHP'],
    ['Adam', 'Bart', 'Lisa']
]


print(L[][])
print(L[][])
print(L[][])


#This is tuple below:
#變的是list,不變得是tuple中的指向

t = ('a', 'b', ['A', 'B'])
t[][] = 'X'
t[][] = 'Y'
print(t)