# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
1.3个基本数据类型,字母、数字、布尔;
2.3个复合数据类型,list(tuple)、set、dict
3.3个复合类型操作,map、filter、reduce
4.3个流程控制,if、for、while
5.3个异常步骤,try、except、finally
6.3个函数,回调、闭包、隐函数(lambda)
7.3个面向对象,class、构造(init)、main
编写时间:2019-02-25
"""
list=[1,2,3]
for i in list:
i+=1
print(i)
from pandas import DataFrame
from pandas import Series
df=DataFrame({
'age':Series([26,85,64]),
'name':Series(['Ben','Joh','Jef'])
})
print(df)
#A=input('从键盘接收输入:')
#print('打印出刚才的输入A:',A)
a=0
if a<0:
print('a<0')
elif a==0:
print('a=0')
else:
print('a>0')
#n=int(input('请输入n:'))
#i=1
#su=0
#for i in range(n+1):
# su+=i
#print(su)
"""
while
"""
#m=input('请输入m: ')
#while(True):
# if(m!='good'):
# print('wrong')
# m=input('请输入m: ')
# else:
# print(m)
# break
#print('while loop is over!')
"""
异常处理
"""
#try:
# print(1/0)
#except Exception as e:
# print('分母不能为零')
#finally:
# print('异常处理后,finally处理项')
#print('自定义异常处理')
"""
函数定义、使用
"""
#def f(x,y):
# z=x**2+y**2
# return z
#
#print(f(2,5))
"""
回调,将函数作为参数带入函数,并在函数内调用
"""
def func(fun1,args):
fun1(args)
def f1(x):
print('f1:',x)
def f2(x):
print('f2:',x)
func(f1,'2')
"""
闭包,将函数作为返回值返回
"""
def say(word):
def name(name):
print(word,name)
return name;
hi=say('hi')
hi('mis wang')
"""
匿名函数
"""
f=lambda x,y:x+y
print(f(1,2))
print((lambda x,y:x**2+y**2)(3,4))
"""
list
"""
s=[1,2,3,4]
print(s[:-2])
s.append(6)
print(s)
s.extend([5,7])
print(s)
s.insert(1,100)
print(s)
s.remove(100)
print(s)
print(s.pop(0))
print(s.count(1))
print(s)
s.reverse()
print(s)
s.sort()
print(s)
s.sort(reverse=True)
print(s)
k=s.copy()
print(k)
"""
元祖tuple与list相似,只是元素一旦确定,不可更改
"""
t=(1,2,3)
print(t)
"""
集合set,具有过滤重复对象的功能
"""
s={1,2,3,4,3,2,1}
print(s)
"""
字典(dict)
"""
d={1:10,2:20,"a":30}
print(d)
"""
map 遍历序列,操作元素,形成新的序列
"""
li=[11,22,33]
new_list=map(lambda a:a+100,li)
print(new_list)
"""
filter 筛选符合条件的元素
"""
li=[111,22,333]
new_list=filter(lambda x:x>22,li)
print(new_list.__str__)
"""
reduce 累计函数
"""
from functools import reduce
li=[11,12,13,13]
print(reduce(lambda arg1,arg2:arg1+arg2,li))
"""
类和实例,是有变量、是有方法,只能在类的内部调用
"""
class Student(object):
__pri='是有变量'
def __init__(self,name,tel):
self.name=name
self.telll=tel
def print_tell(self):
print('%s: %s:' % (self.name,self.telll))
self.__print_pri()
#是有变量
def __print_pri(self):
print('__print_pri',self.__pri)
big=Student('wzj',123)
print(big.print_tell())
"""
main 函数启动入口
"""
def main():
if __name__ =='__main__':
main()