标签:求和 into sele 输出 new 分组查询 select map avg
1.这个程序的出的结果是
class Singleton:
_instance = None
def __new__(cls,*args,**kwargs):
print(‘New‘)
if cls._instance is None:
print(‘Create‘)
cls._instance = super().__new__(cls,*args,**kwargs)
return cls._instance
def __init__(self):
print(‘Initialize‘)
self.prop = None
s1 = Singleton()
s2 = Singleton()
print(s1)
print(s2)
答案是:
New
Create
Initialize
New
Initialize
<__main__.Singleton object at 0x00000202F3E70CC0>
<__main__.Singleton object at 0x00000202F3E70CC0>
答: 列表(list) 字符串(str) 元祖(tuple) 字典(dict) 集合(set) 布尔值(bool)
print(sum(range(1,1001)))
def myfac(n):
if n==1:
return 1
else:
return myfac(n-1)*n
print(myfac(5))
bubble_sort(alist):
for j in range(len(alist) - 1, 0, -1):
# j表示每次遍历需要比较的次数,是逐渐减小的
for i in range(j):
if alist[i] > alist[i + 1]:
alist[i], alist[i + 1] = alist[i + 1], alist[i]
li = [54, 26, 93, 17, 77, 31, 44, 55, 20]
bubble_sort(li)
print(li)
不会
不会
class B(object):
def fn(self):
print(B,‘fn‘)
def __init__(self):
print(B,‘INIT‘)
class A(object):
def fn(self):
print(A,‘fn‘)
def __new__(cls,a):
print(a,‘NEW‘)
if a > 10:
return super(A,cls).__new__(cls)
return B()
a1 = A(5)
a1.fn()
a2 = A(20)
a2.fn()
print(a1)
print(a2)
答案是
5 NEW
<class ‘__main__.B‘> INIT
<class ‘__main__.B‘> fn
20 NEW
<class ‘__main__.A‘> fn
<__main__.B object at 0x000001DF8A5A7128>
<__main__.A object at 0x000001DF8A58C748>
class Father(object):
def __init__(self, age):
self.age = age
print("age: %d" % (self.age))
?
def getAge(self):
print(‘父类的返回结果‘)
return self.age
?
?
class Son(Father):
def getAge(self):
print(‘子类的返回结果:‘)
return self.age
if __name__ == ‘__main__‘:
son = Son(18)
print(son.getAge())
答案是:
age: 18
子类的返回结果:18
(1).写sql语句建表
(2)写sql语句插入2个学生,2个班级
(3)写sql语句,分组查询每个班级的平均分数,并按降序排序,输出,班级编号,班级名,平均分数
list, string, dict, tuple, set, boolean
print(sum(range(1001)))
def f(x):
if x == 1:
return 1
else:
return f(x-1)*x
a = input(‘请输入一个大于0的整数:’)
print(f(a))
def bubble_sort(alist):
for j in range(len(alist)-1,0,-1):
for i in range(j):
if alist[i] > alist[i+1]:
alist[i], alist[i+1] = alist[i+1], alist[i]
li = [54,26,93,17,77,31,44,55,20]
bubble_sort(li)
print(li)
new 5
B init
B fn
new 20
init 20
A fn
sed -i "s/A/B/g" `grep A -rl D` #百度的 看不懂
def a(x):
return x**2
print(map(a,[1,2,3,4]))
#返回结果[1,4,9,16]
class Father():
def __init__(self):
return ‘fathre’
def __del__(self):
return ‘father已经销毁’
class Son(Fathre):
def __init__(self):
return ‘son’
def __del__(self):
return ‘son已经销毁’
①写sql语句建表
②写sql语句加入2班级,2学生
③写sql语句,分组查询出每个班级的平均分数,并按降序排序,输出,班级编号,班级名,平均分数
①:CREATE TABLE IF NOT EXISTS class(
id INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(50)
)
CREATE TABLE student (
id VARBINARY(20),
NAME VARCHAR(50),
class_id INT,
score DOUBLE
)
?
②:INSERT INTO class(NAME) VALUES(‘1803a‘);
INSERT INTO class(NAME) VALUES(‘1804a‘);
INSERT INTO student(id,NAME,class_id,score) VALUES(‘1001‘,‘张三‘,1,88.0);
INSERT INTO student(id,NAME,class_id,score) VALUES(‘1001‘,‘李四‘,1,99.0);
③:SELECT s.class_id,c.`name`,s.sco
FROM(
SELECT class_id,AVG(score) sco
FROM student
GROUP BY class_id
ORDER BY sco DESC)s JOIN class c
ON s.`class_id`=c.`id`
标签:求和 into sele 输出 new 分组查询 select map avg
原文地址:https://www.cnblogs.com/cwx-0324/p/11393365.html