Python: Tuples, Sets, Fractions, Types

Tuples:

T = (1, 2, 3, 4)
len(T)

T + (5, 6)

T.index(4)
T.count(4)

#Tuples are immutable

Sets:

T = (1, 2, 3, 4)
len(T)

T + (5, 6)

T.index(4)
T.count(4)

#Tuples are immutable

Fractions:

from fractions import Fraction
f = Fraction(2, 3)
f+1
f + Fraction(1, 2)

Types:

L = [2, 3, 4]
type(L)	#<class 'list'> for 3.0 or higher

isinstance(L, list)	#True

转载于:https://www.cnblogs.com/kongs/archive/2011/10/28/2227987.html

猜你喜欢

转载自blog.csdn.net/weixin_34326558/article/details/93394979