Python中list的append方法添加,和使用下标取得。之中的元素还可以是其他的数据结构

其中元组和列表最大的一个区别,目前我觉得就是元组是不可修改的,没有append等方法。
#pylist_test.py

class Test:
	i = 0
	def __init__(self):
		pass
	def sayhello(self):
		print 'hello'+str(self.i)
		Test.i = self.i+1
	def geti(self):
		print self.i
	def __del__(self):
		print 'destruct'+str(self.i)

def main():
	li = list()
	j = int()
	j = 0
	seq = (1,2,3,4,5)
	#print len(seq)
	for i in seq:
		for i in seq:
			li.append(Test())
			li[j].sayhello()
			j = j + 1
		print "come here 01!"
		li[i-1].geti()
	print len(li)
	print "come here o2!"

main()
#print len(li)
print "come here 03!"


#Tuple To List
#>>> li = list((1,2))
#[1,2]
#List To Tuple
#>>> tu = tuple([1,2])
#(1,2)


#we can declare a specific type variable obviously
#size = int()
#size = 1
#print type(size),size
#size = 'test'
#print type(size),size

#list_test = list()
#print type(list_test)

#t1 = Test()
#t2 = Test()
#t3 = Test()

#list_test.append(t1)
#list_test.append(t2)
#list_test.append(t3)
#list_test[0].sayhello()
#list_test[1].sayhello()
#list_test[2].sayhello()

#list can be nested in Python
#list_2 = list()
#list_2.append(list_test)
#list_2[0][0].sayhello()
#list_2[0][1].sayhello()
#list_2[0][2].sayhello()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值