python day2
Today is the second day of leaning Python. 1.For Loop ?? for i in range(): 2.break and continue ?? break : To jump out of this loop ?? continue : To jump out of the current loop 3.list? [] ?? a = [1,2,3,4,5]???? a[1:4]? Everying from the first to the fourth,but not the fourth. ????????????????????????????? a[1:]??? from the first to the last ????????????????????????????? a[1: :2] This 2 represents the step size.(2,4) if it‘s -2? represents in the opposite direction ????????????????????????????? a.append(‘data‘)? a.insert(index,‘data‘) ????????????????????????????? a.remove(‘data‘)? a.pop(index) If no input index,it means that the last item is deleted. ????????????????????????????? a.count(‘data‘) ? ? a.extend(b)? Add b to a ? ? a.index(‘data‘)? Find index??? ????????????????????????????? a.sort()?? Sort lists from samll to large??? a.reverse()?? Reverse the contents of the list 4.tuple? () ?? a=(1,5)????? Tuples are readable and unchangeable. 5.Format output ?? print ("----%s----" % variable) 6.Determine whether the user input is a number? ??? if variable.digit():?? If it‘s number,return True? Else return False 7.dictionary ?? dic={"name":"Mr","age":22,"sex":"man"}??? Key-value pairs ?? Key is Immutable? Changeless . It could be a string,a number or a tuple ?? Value is Varibale . it could be a list,a string,a number ?? The contents of the dictionary are disordered.? Access accordng to Key. ? ?? 8.Shopping test? (source code) salary = input("请输入您的工资:") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |