import json
class Students(object):
def read(s):
return r'["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
class Students(object):
def read(s):
return r'["Tim", "Bob", "Alice"]'
s = Students()
print json.load(s)
2018-02-23
class Person(object):
count = 0
def __init__(self,name):
Person.count += 1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
count = 0
def __init__(self,name):
Person.count += 1
p1 = Person('Bob')
print Person.count
p2 = Person('Alice')
print Person.count
p3 = Person('Tim')
print Person.count
2018-02-23
class Person(object):
def __init__(self,name,gender,birth,job):
self.name=name
self.gender=gender
self.birth=birth
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
def __init__(self,name,gender,birth,job):
self.name=name
self.gender=gender
self.birth=birth
self.job=job
xiaoming = Person('Xiao Ming', 'Male', '1990-1-1', job='Student')
print xiaoming.name
print xiaoming.job
2018-02-23
class Person(object):
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,key = lambda x:x.name)
print L2[0].name
print L2[1].name
print L2[2].name
pass
p1 = Person()
p1.name = 'Bart'
p2 = Person()
p2.name = 'Adam'
p3 = Person()
p3.name = 'Lisa'
L1 = [p1, p2, p3]
L2 = sorted(L1,key = lambda x:x.name)
print L2[0].name
print L2[1].name
print L2[2].name
2018-02-23
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-02-23
from os import path
print path.isdir(r'/data/webroot/')
print path.isfile(r'/data/webroot/')
print path.isdir(r'/data/webroot/')
print path.isfile(r'/data/webroot/')
2018-02-23
def performance(unit):
def mid(f):
@functools.wraps(f)
def ins(*arg,**kw):
print 'call%s()... %s%s' % (f.__name__,time.time(),unit)
return f(*arg,**kw)
return ins
return mid
def mid(f):
@functools.wraps(f)
def ins(*arg,**kw):
print 'call%s()... %s%s' % (f.__name__,time.time(),unit)
return f(*arg,**kw)
return ins
return mid
2018-02-23
def calc_sum(lst):
def lazy_sum():
def add_all(x,y):
return x*y
return reduce(add_all, list)
return lazy_sum
f = calc_sum([1, 2, 3, 4])
print(f())
def lazy_sum():
def add_all(x,y):
return x*y
return reduce(add_all, list)
return lazy_sum
f = calc_sum([1, 2, 3, 4])
print(f())
2018-02-22
class Person(object):
__count = 0
@classmethod
def how_many(cls):
return cls.__count
def __init__(self, score):
self.score = score
Person.__count = 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, score):
self.score = score
Person.__count = Person.__count + 1
print Person.how_many()
p1 = Person('Bob')
print Person.how_many()
感觉题目说的乱七八糟的
2018-02-22
在3.0中,需要用list()构造。
也就是最后一句改为: print(list(filter(is_sqr, range(1, 101))))
也就是最后一句改为: print(list(filter(is_sqr, range(1, 101))))
2018-02-22
from __future__ import unicode_literals
s = 'am I an unicode?'
print isinstance(s, unicode)
Nice,你这是年薪过百万的节奏啊!下一节吧。
s = 'am I an unicode?'
print isinstance(s, unicode)
Nice,你这是年薪过百万的节奏啊!下一节吧。
2018-02-22
import os
print os.system('pwd')
查看当前目录是/data/webroot,并没有下面的文件和文件夹。
第一个为True就可以通过。
print isdir(r'/data/webroot/')
print os.system('pwd')
查看当前目录是/data/webroot,并没有下面的文件和文件夹。
第一个为True就可以通过。
print isdir(r'/data/webroot/')
2018-02-22