https://www.youtube.com/watch?v=W8KRzm-HUcc
courses = ['History', 'Math', 'Physical', 'ComSci']
print(courses)
'''
out:
['History', 'Math', 'Physical', 'ComSci']
'''
print(len(courses))
'''
out:
4
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
print(courses[3]) #等同于Courses[-1]
'''
out:
ComSci
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
print(courses[0:2]) # not including second index & 等同于courses[:2]
'''
out:
['History', 'Math']
'''
print(courses[2:]) # 等同于courses[2:len(courses)-1]
'''
out:
['Physical', 'ComSci']
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
courses.append('Art')
print(courses)
'''
out:
['History', 'Math', 'Physical', 'ComSci', 'Art']
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
courses.insert(0, 'Art') # the first argument is location, the second one is the value of item
print(courses)
'''
out:
['Art', 'History', 'Math', 'Physical', 'ComSci']
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
courses_2 = ['Art', 'Education']
courses.insert(0, courses_2)
print(courses)
'''
out:
[['Art', 'Education'], 'History', 'Math', 'Physical', 'ComSci']
'''
print(courses[0])
'''
out:
['Art', 'Education']
'''
####################################
# correct way
courses = ['History', 'Math', 'Physical', 'ComSci']
courses_2 = ['Art', 'Education']
courses.extend(courses_2)
print(courses)
'''
out:
['History', 'Math', 'Physical', 'ComSci', 'Art', 'Education']
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
courses.remove('Math')
print(courses)
'''
out:
['History', 'Physical', 'ComSci']
'''
# remove the last one
courses = ['History', 'Math', 'Physical', 'ComSci']
poped = courses.pop()
print(poped)
print(courses)
'''
out:
ComSci
['History', 'Math', 'Physical']
'''
courses = ['History', 'Math', 'Physical', 'ComSci']
courses.reverse()
print(courses)
'''
out:
['ComSci', 'Physical', 'Math', 'History']
'''