在python3中做了些修改,输出前需要使用list()进行显示转换
def is_sqr(x):
return (math.sqrt(x) % 1 ==0) #判断列表中的元素开平方后是不是整数,是整数就返回
print(list(filter(is_sqr,range(1,101))))
def is_sqr(x):
return (math.sqrt(x) % 1 ==0) #判断列表中的元素开平方后是不是整数,是整数就返回
print(list(filter(is_sqr,range(1,101))))
2018-01-25
def performance(f):
def prr(x):
print 'clever'
return f(x)
return prr
@performance
def f(x):
return x**2
print f(3)
def prr(x):
print 'clever'
return f(x)
return prr
@performance
def f(x):
return x**2
print f(3)
2018-01-25
class Person(object):
__count = 0
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
@classmethod
def how_many(cls):
return cls.__count
def __init__(self,name):
self.name=name
Person.__count+=1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2018-01-25
说 课程难老师坑没照顾新手 的,可以滚啊,自己脚大买了不合适的鞋子,活该穿小鞋,还那么多人点赞,活该被人超越,不从自身找原因,怨这个怨那个,就俩字“活该”
2018-01-25
def calc_prod(lst):
def ji():
def a(x, y):
return x*y
return reduce(a, lst)
return ji
f = calc_prod([1, 2, 3, 4])
print f()
def ji():
def a(x, y):
return x*y
return reduce(a, lst)
return ji
f = calc_prod([1, 2, 3, 4])
print f()
2018-01-25
import math
def is_sqr(x):
tmp = math.sqrt(x)
return tmp == int(tmp)
print filter(is_sqr, range(1, 101))
def is_sqr(x):
tmp = math.sqrt(x)
return tmp == int(tmp)
print filter(is_sqr, range(1, 101))
2018-01-24
个人感觉应该是这样的 f1,f2,f3 = count() 其实是 f1,f2,f3 = fs[0],fs[1],fs[2] 也就是说 类似 a,b,c = [1,2,3] 这种格式 所以输出 1,4,9是正确的
2018-01-24
# -*- coding: utf-8 -*-
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score
def get_grade(self):
if self.__score >=90:
return 'A-优秀'
elif self.__score >=60:
return 'B-及格'
return 'C-不及格'
class Person(object):
def __init__(self, name, score):
self.name = name
self.__score = score
def get_grade(self):
if self.__score >=90:
return 'A-优秀'
elif self.__score >=60:
return 'B-及格'
return 'C-不及格'
2018-01-24
class Person(object):
__count = 0
def __init__(self,name):
self.name = name
Person.__count += 1
@classmethod
def how_many(cls):
return cls.__count
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
__count = 0
def __init__(self,name):
self.name = name
Person.__count += 1
@classmethod
def how_many(cls):
return cls.__count
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
2018-01-24
import math
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
def add(x, y, f):
return f(x) + f(y)
print add(25, 9, math.sqrt)
2018-01-24
try:
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
import json
except ImportError:
import simplejson as json
print json.dumps({'python':2.7})
2018-01-24
from os.path import isdir,isfile
print isdir(r'/data/webroot/resource/python')
print isfile(r'/data/webroot/resource/python/test.txt')
输出的都是False
print isdir(r'/data/webroot/resource/python')
print isfile(r'/data/webroot/resource/python/test.txt')
输出的都是False
2018-01-24