python系列3(list tupe dict )

1. list tupe dict 的区别

li = [1,2,'abc','def']
tup = (1,2,'abc','def') #不允许改变,类似一种常量的概念

2. list tupe 的实例

#!/usr/bin/python
import os
'''
list for define
'''
list = [1,2,'x',3]
for i in list:
	'''
	if i == 'x':
		break
	'''
	print i
print "======list[i]======="
for i in range(5):
	print list[i]
	
'''
tupe for define
'''
tup = ('abc',1,3,'def')
for i in tup:
	print i
else:
	print "input the right number"
	
'''
for file define
'''
str = open('for_file.py','r').readline()
print str
for line in str:
	print line
else:
	print 'out readline'

3.  list tupe string 的相互转换

#/usr/bin/python
import string
str = 'abcdefg'
li = list(str)
for i in li:
	print i
	
tup =  tuple(str)
print tup
for i in tup:
	print i

li = [1,2,'abs',3]
s = ';'.join(li)
print s

#int 要转换成string 不能隐性转换


你可能感兴趣的:(python系列3(list tupe dict ))