这个运行结果的名称一直是null,找了好几遍没找到问题
下面是源码:
http_server2.zip
箭头所指的这串字符是什么意思?io的地址?
class Employee: id=1000 name=None salary=None def __add__(self,other): if isinstance(other,Employee): return '{0}'.format(self.salary+other.salary) else: return '不是同类对象,不能相加' def __init__(self,name,salary): self.name=name self.salary=salary Employee.id+=1 @property def salary1(self): return '{0}月薪为{1}'.format(self.name,self.salary) @salary1.setter def salary1(self,salary): if (1000<salary<50000): self.salary=salary else: print('请输入1000-50000范围内的薪资') a = Employee('NG',-4000) print(Employee.id) print(a.salary1) b = Employee('LY',8000) print(Employee.id) print(b.salary1) print(a.__add__(b))
老师,为什么setter方法没有发挥作用。
老师这里为什么要使用子查询,我尝试使用普通的select语句好像也能正常执行
尤其是sumdecode那部分
单行函数是在分组之前执行吗?最后那个练习题的执行顺序是什么?
老师,我在安装PyCharm的时候出现,需要勾选吗
你好老师
问题:我用管程法实现了多线程的操作(用synchronized的方法)但是还是出现了脏数据;
package Thread_study03; /** * 协作模型:生产者消费者实现方式一:管程法 * 借助缓冲区 * @author 陈世丰 * */ public class CoTest01 { public static void main(String[] args) { // TODO Auto-generated method stub SynContainer synContainer= new SynContainer(); new Thread(new Productor("a",2,synContainer)).start();//生产2 new Thread(new Consumer("m",4,synContainer)).start();//消费4 new Thread(new Productor("a1",4,synContainer)).start();//生产4 new Thread(new Consumer("m1",2,synContainer)).start();//消费2 } } class SynContainer{ Steamedbun[] buns = new Steamedbun[10]; //存储容器 int count = 0; //计数器 //生产 public synchronized void push(Steamedbun a) throws InterruptedException{ if(count>=10){ this.wait(); } buns[count]=a; count+=1; this.notify(); } //消费 public synchronized Steamedbun pop() throws InterruptedException{ if(count<=0){ this.wait(); } Steamedbun a=buns [count]; buns [count]=null; count-=1; this.notify(); return a; } } //馒头类 class Steamedbun{ int id; public Steamedbun(int id) { this.id = id; } } //生产者 class Productor implements Runnable{ String name; int count ; SynContainer synContainer; public Productor(String name, int count,SynContainer synContainer) { this.name = name; this.count = count; this.synContainer=synContainer; } @Override public void run() { for(int i=0;i<count;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { synContainer.push(new Steamedbun(i)); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(name+"成产后剩余-->"+synContainer.count+"剩余个馒头"); } } } //消费者 class Consumer implements Runnable{ String name; int count; SynContainer synContainer; public Consumer(String name, int count, SynContainer synContainer) { this.name = name; this.count = count; this.synContainer = synContainer; } @Override public void run() { // TODO Auto-generated method stub for(int i=0;i<count;i++){ try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { synContainer.pop(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(name+"消费后剩余-->"+synContainer.count+"个馒头"); } } }
Training.rar
老师,任意字符串用单引号还是双引号,还是都可以?
老师啊,''' 三个单引号不是注释用的吗,这又可以创建多行字符串,搞得有点晕啊。
>>> a = [1,2,3] >>> b = list(range(10,50,10)) >>> a.insert(2,b) >>> a [1, 2, [10, 20, 30, 40], 3] >>> a[2] [10, 20, 30, 40]
请问老师,我原意是想把b列表的元素插入a列表的第三个位置,但是使用insert后发现,a列表的第三位元素还是一个列表,怎么样才能在列表中特定位置插入新的列表,就是上面最终让a列表的第三位为10
老师,能发一下视频里的dtree资料吗,源码里面没有相关的帮助文档,下载的资料里面也没有tree
请问这种情况怎么办?
密码怎么设都能登?
账号也是
老师好,请问集合如果类似字典中的键,是否意味着键的性质字典也适用于集合的元素?即:
(1)集合元素不能修改,如果要修改,需要先删除这个元素,再增加一个新元素
(2)集合中不能有列表的存在:如{[1,2],3,4}
(3)集合中不能存在字典:如{{'a':1},2,3}
(4)结合中不能存在集合,即不存在类似二维列表一样的二维集合一说:如{{1,2,3},4,5,6}
老师好,在集合中插入一个新元素,新元素在集合的位置是否固定呢?
如:
>>> a={3,4,5}
>>> a.add(9)
>>> a
{9, 3, 4, 5}
>>> a.add(1)
{1, 3, 4, 5, 9}
>>> a.add(20)
{1, 3, 4, 5, 9, 20}
第一次add(9)时候,9放在了最前面,之后1,20,都是按照从大到小排列
又如:
>>> a=['a','b','c','d']
>>> b=set(a)
>>> b
{'d', 'a', 'c', 'b'}
>>> a=['a','b','c','b']
{'a', 'c', 'b'}
几次排列均不同。
是否可以理解为:因为集合无序可变,所以插入新元素的位置也是无序的。
另外,字典中如果插入新键值对,是否也同样是插入的位置是随机的。谢谢
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637