学习Python第八天

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# def f1(x):
# return x>22
# # ret = filter(f1,[11,22,33,44])
# ret = filter(lambda x:x>22,[11,22,33,44])
# for i in ret:
# print(i)

# map
# def f1(x):
# return x + 100
# ret = map(f1, [1, 2, 3, 4])
# print(ret)
# for i in ret:
# print(i)
# print('###################')
# ret = map(lambda x: x + 100, [1, 2, 3, 4])
# for i in ret:
# print(i)

# dic = {
# 'ff0':1
# }
#
# ret = hash('ff0')
# print(ret)
#
# li = [11,22]
# #判断某个对象是否是某个类创建的
# r = isinstance(li,list)
# print(r)
#
# a = range(10)
# for i in a:
# print(i)

# obj = iter([11,22,33,44])
# ret = next(obj)
# ret2= next(obj)
# print(ret)
# print(ret2)

# li = [11,22,12,323,132]
# r = max(li)
# print(r)
# r = min(li)
# print(r)

# i = pow(2,10,10) #基数,次方,取余
# print(i)
# 四舍五入
# r = round(3.3)
# print(r)

# li = [11,22,33,44]
# # for i in li:
# # print(i)
# li2 = ['a','b','c','d','f']
# ret = zip(li,li2)
# for i in ret:
# print(i)

# 数字转换成字母:chr(数字)
# i = chr(65)
# print(i)

# import random
# temp = ''
# for i in range(6):
# num1 = random.randrange(0,4)
# if num1 == 3 or num1 == 1:
# num3 = random.randrange(0,10)
# temp +=str(num3)
# else:
# num = random.randrange(65, 91)
# c = chr(num)
# temp += c
# print(temp)

# li = [1,3,441,11,22,32,2]
# a = sorted(li)
# print(a)
# li=['b','a','ac']
# a = sorted(li)
# print(a)

# 1,打开文件 2、操作文件 3、关闭文件
# open(文件名/路径,模式(只读)(只写)等,编码) 默认是只读模式 ‘r'

# f = open('../test','r')

# 只读
# data = f.read()

# 只写,并清空原文件里的内容,如果没有该文件则创建,w
# f = open('../test','w')
# f.write('123')
# print(f)

# 只写模式【不可读,不存在则创建,存在则报错】 x
# f = open('D:/TEST.txt','x')
# f.write('111')
# print(f)

# 追加模式,不可读,不存在则创建 a
# f = open('../test','a')
# f.write('123')
# f.close()

# 字节方式打开 只读,rb
# f = open('../test1','rb')
# data = f.read()
# print(type(data))
# print(data)
# f.close()

# f = open('../test','r',encoding='utf-8')
# data = f.read()
# f.close()
# print(data)

# # 1,只读,rb
# f = open('../test','rb')
# data = f.read()
# f.close()
# print(data)

# r+
# f = open('test','r+',encoding='utf-8')
# print(f.tell()) #获取当前指针
# data = f.read(3)
# print(f.tell()) #获取当前指针
# print(type(data),data)
# f.write('~~~fdafda')
# f.seek(0)#让指正回到起始位置
# data = f.read()
# print(type(data),data)
# f.close()

# w+ 先清空,重写之后才可以读
# f = open('test', 'w+', encoding='utf-8')
# f.write('fffff!!!')
# f.seek(0)
# data = f.read()
# print(data)
# f.close()

# x+ 如果文件存在就报错

# a+ 打开的同时,指针已经到最后
# f = open('ha', 'a+', encoding='utf-8')
# f.seek(0)
# data = f.read()
# print(data)
# f.close()

# f.tell() 获取指针的位置
# f.seek(num) 调整指针的位置
# f.write() 写内容
# f.read() 读取内容

# f = open('ha','r+',encoding='utf-8')
# temp = f.readline() #只读取一行
# f.flush()
# #依赖于指针
# f.truncate()
# f.write('ffff')
# print(temp)
#
# f.close()

# f = open('ha','r',encoding='utf-8')
# for line in f:
# print(line)
# f.readline()

# f = open('ha','r',encoding='utf-8')
# d = open('test','w')
# for line in f:
# d.write(line)
# f.close()
# d.close()

# def f3(arg):
# print('aaa')
# def x():
# print('bbbb')
# f3(x)

# arg =>代指函数,arg()执行函数
# arg =>arg是变量
# result = []
# def MyFilter(func,seq):
# for i in seq:
# e = func(i)
# if e:
# result.append(i)
# return result
# def f1(x):
# if x>22:
# return True
# else:
# return False
#
# a = MyFilter(f1,[11,22,33,44,55])
# print(a)
# res = []
# li = [11, 22, 33, 44, 55]
#
#
# def x(arg):
# return arg + 100
#
#
# def MyMap(fun,arg):
# for i in arg:
# ret = fun(i)
# res.append(ret)
# return res
# a = MyMap(x,li)
# print(a)

posted @ 2017-11-27 10:07  枫絮  阅读(142)  评论(0编辑  收藏  举报