def print(isChinese,name,familyName): def inner_print(a,b): print("{0} {1}".format(a,b)) if isChinese: inner_print(familyName,name) else: inner_print(name,familyName) printName(True,"百","二")
显示
File "D:\python-exec\mypy001\测试嵌套函数(内部函数)的定义.py", line 18, in <module>
printName(True,"百","二")
NameError: name 'printName' is not defined
是哪儿不对呢?
老师 这个怎么run不出来啊
老师,明明在@property 下面的函数中有print语句 ,但是不能通过s.score = 100 来运行,不是里面有print语句吗,为什么还要通过print(s.score)来打印,明明@score.setter下面的函数中都能够之间运行print里面的语句。
使用__new__()方法创建实例对象时
实例对象的属性对象创建是不是深拷贝。
实例对象的方法对象创建是不是浅拷贝。
老师你好,关于赋值与地址传递问题:在IDLE中[-5,255]有整数缓存,为什么在“a=1000;b=a”中a的地址可以传递给b,且保持不变呢?这两种赋值有什么区别呢?
a="setsetset" print(a[::-2])
结果为啥是tsets而不是etse
class ComputerFactory: __obj = None __init_flag = True __countLenovo = 0 __countAsus = 0 __countHasee = 0 def __new__(cls, *args, **kwargs): #单例模式 if cls.__obj==None: cls.__obj = object.__new__(cls) return cls.__obj #new方法创建完成一定要返回我们的实例对象 def __init__(self): #单例模式 if ComputerFactory.__init_flag: print('构造初始化') ComputerFactory.__init_flag = False def produce(self,brand): #工厂模式 if brand =='联想': ComputerFactory.__countLenovo += 1 return Lenovo() elif brand == '华硕': ComputerFactory.__countAsus += 1 return Asus() elif brand == '神舟': ComputerFactory.__countHasee += 1 return Hasee() def calculate(self): a = [ComputerFactory.__countAsus,ComputerFactory.__countLenovo,ComputerFactory.__countHasee] print('本公司一共生产了{0}台电脑'.format(sum(a)) class Computer: __count = 0 def __init__(self): Computer.__count +=1 def calculate(self): print('生产了{0}台电脑'.format(Computer.__count)) class Lenovo(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Lenovo.__num +=1 def calculate(self): print('共生产了{0}个联想电脑'.format(Lenovo.__num-1)) class Asus(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Asus.__num += 1 def calculate(self): print('共生产了{0}个联想电脑'.format(Asus.__num-1)) class Hasee(Computer): __num = 0 def __init__(self): # Computer.__init__(self) Hasee.__num += 1 def calculate(self): print('共生产了{0}个联想电脑'.format(Hasee.__num-1)) t = ComputerFactory() h = Computer() t.produce('联想') h.calculate() Lenovo().calculate() t.calculate() Lenovo().calculate()
问题:不知道为啥会报这样的错,我反复核实没有格式的错误啊,求指导!老师
老师,您好,PPT上写保存为文件执行时,解释器会做一部分优化,范围是(-5,任意正整数),我试了,把a和b都在这个范围内,但是我去的是小数,(浮点数),运行结果还是True,那为什么要强调任意整数呢?小数也OK。
老师请问,在.py文件里运行io,怎么输出修改后的字符串呢?
还有我直接打印b也都是返回<_io.StringIO object at 0x035F6A30>。
>>> a = "gedaqiwei" >>> import io >>> b = io.StringIO(a) >>> b.getvalue() 'gedaqiwei' >>> b.seek(7) 7 >>> b.write("E") 1 >>> b.getvalue() 'gedaqiwEi' >>> b <_io.StringIO object at 0x035F6A30> >>> print(b) <_io.StringIO object at 0x035F6A30> >>>
f = "我是{0},我的存款有{1.2f}" f.format("崔",6244.2212) print(f) 为什么运行不了啊
联想截图_20250218200530.png
为啥我这个没有窗口
upper()是转换字符串大小写的意思吗?
s.upper()=='Q':
是指s这个变量里面如果获取到的是字符q或者Q都将他们转换一下大小写吗?还是说小写的q转换大写的就保留呢?
老师,如果在get语法中,输出两个键,为什么运行后只取到一个键值呢
老师,为什么这两个人f1()的结果不一样
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637