| ???? Python ??? | ??9?? ????? | |
|---|---|---|
| ???? | ??? | ???? |
?????б???????????????????????????? ?????? ???????????顣???????????????????????????塣?????????????????????????????????????????????????????????????????
#!/usr/bin/python
# Filename: using_tuple.py
zoo = ('wolf', 'elephant', 'penguin')
print 'Number of animals in the zoo is', len(zoo)
new_zoo = ('monkey', 'dolphin', zoo)
print 'Number of animals in the new zoo is', len(new_zoo)
print 'All animals in new zoo are', new_zoo
print 'Animals brought from old zoo are', new_zoo[2]
print 'Last animal brought from old zoo is', new_zoo[2][2]
????????code/using_tuple.py??
$ python using_tuple.py
Number of animals in the zoo is 3
Number of animals in the new zoo is 3
All animals in new zoo are ('monkey', 'dolphin', ('wolf', 'elephant', 'penguin'))
Animals brought from old zoo are ('wolf', 'elephant', 'penguin')
Last animal brought from old zoo is penguin
????zoo???????飬???????len?????????????????????????????????????????????
????????????????????????????????????????new_zoo?????????Щ???????????????????????????????????????????????????鯔????????????
???????????????????????????????λ??????????????е????????????????б???÷???????????? ???? ??????????????new_zoo[2]??????new_zoo?е??????????????????new_zoo[2][2]??????new_zoo????????????????????????
????0????1?????????顣???????????????????????????myempty = ()??????????е?????????????????????????????????Ψ????????????????????????Python???????????????????????????????????????????????????????2?????????????????singleton = (2 , )??
??Perl??????????
?б???е??б?????????????????б??????Perl????????????????????е???飬???б??е???飬??????е??б??????????????Python??????????????????????洢?????
???????????÷?????????????У???????????????
#!/usr/bin/python
# Filename: print_tuple.py
age = 22
name = 'Swaroop'
print '%s is %d years old' % (name, age)
print 'Why is %s playing with that python?' % name
????????code/print_tuple.py??
$ python print_tuple.py
Swaroop is 22 years old
Why is Swaroop playing with that python?
print????????????%?????????????????????Щ???????????????????????????????????????????????????%s??????????%d????????????????????????????????Щ?????
?????????????????飬???????????%s??????????name??????????е???????????????????????%d??????????????????age??
Python???????????????????е????????????????????????????????滻?????λ?á????%s???滻?????name??????????????
print??????÷?????д?????ü???????????????????????????????????????????????????????
??????????????????%s?????????Python???????????????顣????????????????Ч????????????????????????????????????????????????????????
??????print????У?????????????????????????%?????????????????????????????????????????????????????Ч??
| ???? | ????? | ???? |
|---|---|---|
| ?б? | ??? | ??? |