#可变类型的对象为全局变量时
#MAP can iterate directly, no need to write a for loop
#方法一:
foo = [2,18,9,22,17]
# Mapdemo = map (lambda x:x*2+10,foo)
# for I in Mapdemo:
# Print (i)
# #方法二:
# def TT (x):
# return X*2+10
# M=TT
# Print ("m={0}". Format (m))
# mresult=m (12)
# print ("mresult=%d"%mresult)
# Result=map (Tt,foo)
# Print ("result:{0}". Format (Result))
#加括号是函数的引用, no parentheses are called functions
# F=filter (Lambda X:x>10,foo) #过滤满足条件的结果
# print (f)
# for I in F:
# Print (i)
#
# #reduce () add and subtract functions
# from Functools import reduce
# # R=reduce (Lambda X,y:x+y,foo)
# # print ("r={0}". Format (R))
# Def re (x, y):
# return X+y
# r=reduce (Re,foo)
# Print ("r={0}". Format (R))
#
# #算数函数直接调用
# Print (SUM (foo))
# Print (max (foo))
# Print (min (foo))
#
# print (sorted (foo)) #sorted函数会生成一个新的列表, does not change the value of the original list
# Print (foo)
#
# s=sorted (foo,reverse=true) #倒序排序
# print (s)
#
# dict1={"A": 1, "D": 3, "C": 2}
# print (Sorted (Dict1.items ()))
# def _gt_ (Self,other):
# if Self.obj>other:
# Self.obj=obj
#
# Print (Sorted ([1,2,3,4,5,6,7],key=reversed_cmp ()))
#.sort () Sorts the original list and then updates the value of the original list, with no return value sorted the function generates a new list, does not change the value of the original list and has a return value
# a=[' BBB ', ' aaa ', ' CCV ', ' Zoo ']
# print (sorted (a,key=str.lower)) #根据字符串大小写进行排序
#
# #self代表当前对象
# class Person:
# def __init__ (self,sex=none): #初始化函数
# Self.sex=sex
# Def eat (self):
# print ("Eating Now")
# Def sleep (self):
# print ("Sleeping ....")
# def Say (self):
# Print (self.name,self.age,self.sex)
# P=person ("female")
# p.eat ()
# P.sleep ()
#
# #添加属性
# p.name= ' phone '
# p.age=85
# P.say ()
Class Student (object):
def __init__ (Self,name=none,age=none,sex=none):
Self.name=name
Self.age=age
Self.sex=sex
def study (self):
Print ("{0} in learning". Format (Self.name), "Age: {0}". Format (self.age), "Gender: {0}". Format (Self.sex))
A=student (' Harry ', 18, ' female ')
A.study ()
#封装
#get/set do not write _init_ () are public properties in Init
#私有方法def__study () starts with--can only be used inside a function
#自动销毁方法__del__
def _del_ (self):
Print ("Object is being destroyed ...")
S=student ("Zhang San")
S.study ()
Print (s)
Python fourth lesson map, function Reference, sort, object