python_L6

1. tuples:

  (3) -> 3 but (3,) indicates a tuple -> (3,)  

2. tuples and lists:

  tuples:num = (1,2,3)  (3,)  不可修改  num(1) = 4  -> ‘error‘

  lists:num = [1,2,3]   [3]  可以修改   num[1] = 4 -> [1,4,3]

.

## universities

Techs = [‘MIT‘, ‘Cal Tech‘]
Ivys = [‘Harvard‘, ‘Yale‘, ‘Brown‘]

Univs = [Techs, Ivys]
Univs1 = [[‘MIT‘, ‘Cal Tech‘], [‘Harvard‘, ‘Yale‘, ‘Brown‘]]

Techs.append(‘RPI‘)

print(‘Univs = ‘)
print(Univs)
print(‘‘)
print(‘Univs1 =‘)
print(Univs1)

for e in Univs:
    print(‘Univs contains ‘)
    print(e)
    print(‘   which contains‘)
    for u in e:
        print(‘      ‘ + u)
时间: 2024-10-10 17:30:44

python_L6的相关文章