pythonシリーズ3(list tupe dict)

1104 ワード

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