Learning Python(5) Sequence type(lists, tuples, strings)

common operations:

	len(s)		length of s	
	min(s)		smallest item of s	
	max(s)		largest item of s	
	x in s		1 if an item of s is equal to x, else 0
	x not in s	0 if an item of s is equal to x, else 1
	s + t		the concatenation of s and t	
	s * n, n * s	n copies of s concatenated	
	s[i]		i'th item of s, origin 0
	s[i:j]		slice of s from i to j	

	slice from index i up to but not including index j
	i defaults to 0, j to len(s)
	negative goes from right-end of sequence


slice from index i up to but not including index j
i defaults to 0, j to len(s)
negative goes from right-end of sequence


List is like array in other language

Tutples are like list, but they are immutable.


list reference

	s[i] = x	item i of s is replaced by x	
	s[i:j] = t	slice of s from i to j is replaced by t	
	del s[i:j]	delete slice (same as s[i:j] = [])
	s.append(x)     add x to end of s
	s.count(x)	return number of i's for which s[i] == x
	s.index(x)	return smallest i such that s[i] == x1)
	s.insert(i, x) 	item i becomes x, old item i is now at i+1, etc.
	s.remove(x) 	same as del s[s.index(x)]	
	s.reverse() 	reverses the items of s (in place)
	s.sort()	sorts the list (in place)
			Optional parameter: function of two arguments 
			returning -1, 0 or 1 depending on whether arg1 
			is >, ==, < arg2.

example:

L = [ 'abc', 123, 1.23]
len(L) //3
L.append(3)
L
['abc', 123, 1.23, 3]









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值