a='to be or not to be' b=a.split('be') c="*".join(a) print(c) print(b)
输出结果:
t*o* *b*e* *o*r* *n*o*t* *t*o* *b*e ['to ', ' or not to ', '']
我已经领悟了,老师!
str0 = 'Good good study!' print(id(str0)) b = str0[::] print(b) print(type(b)) print(id(b)) b = "Good good study, Day day up!" print(str0) # 遇到的问题是:b是str0切片得到的字符串,我想着应该是str0的副本才对,也就是说a,b的改变不影响另一个变量,因为a,b所引用的对象不同 # 可是a,b打印出来的地址确实一样的。
老师,如果我还想加一个 if 语句表示说如果输入的s(员工工资)不是数字,即不小心输入了字母,也会报错且print出让“重新输入正确的薪资”。这个 if 语句应该怎么写?
谢谢
s=input("输入一个数字:") print(int(s) if int(s)<10 else "shuzitaida")
老师请问为什么这么写就会报错 而
s=input("输入一个数字:") print(s if int(s)<10 else "shuzitaida")
这样就是对的呢
老师 后面运行的时候为什么会出现中括号啊
del 语句删除的是栈内存a,还是把栈内存和堆内存都删除了;
栈内存和堆内存的关系是一一对应,缺一不可的吗
class ComputerFactory: __count=None def __init__(self,name): self.name=name def __new__(cls,*args,**kwargs): if cls.__count==None: cls.__count=object.__new__(cls) return cls.__count def shengchan(self,a): if a=="联想": return LianXiang() elif a=="华硕": return HuaShuo() elif a=="神舟": return ShenZhou() else: print("输入错误") class Computer: def calculate(self): print("我是电脑,我会计算") class LianXiang(Computer): def calculate(self): print("我是联想") class HuaShuo(Computer): def calculate(self): print("我是华硕") class ShenZhou(Computer): def calculate(self): print("我是神舟") #测试单例模式 x=ComputerFactory("aa") print(x) y=ComputerFactory("bb") print(y) #测试工厂模式 d1=x.shengchan("联想") d1.calculate() d2=x.shengchan("华硕") d2.calculate() d3=x.shengchan("神舟") d3.calculate()
结果:
所以为什么y返回的是None呢?
time start3=time.time() i (): result=[] c=i*z=m*m (): result.append(c+z) end3=time.time() (.format((end3-start3)))
老师把i,m都提出来可以吗
这个C选项是错的吧,视频里说是对的,有点疑惑,求解
老师,为什么我的会报错?
import time time1=time.time() a="" for i in range(100000): a+="sxt" time2=time.time() print("+连接的运算时间:"+str(time2-time1)) #for循环将两种连接符("+","join")做效率对比 time3=time.time() li=[] for i in range(100000): li.append("sxt") b="".join(li) time4=time.time() print("join()连接的运算时间:"+str(time4-time3)) #经过对比join效率跟快(join()连接的运算时间:0.005468130111694336),然后"+"效率太慢(+连接的运算时间:0.3160719871520996)
问题1.为什么十进制2223使用chr不能转换成字符??
import turtle #导入海龟绘图模块 turtle.showturtle()#显示箭头 turtle.write("高淇,你好,我是小海龟") turtle.forewrad(300)#前进300个像素 turle.color("red")#画笔改变颜色:red turtle.left(90) turtle.forwrd(300)_ turtle.goto(0,50)#去坐标(0,50) turtle.goto(0,0) turtle.penup() #抬起笔。这样,移动时,路径不会画出来 tuerle.goto(0,300) tuerle.pendown() tuerle.circle(100)#画圆 tuerle.done()#程序结束,保持窗口存在
是不是这样子4*5是0到19,然后每个四个输出一个
老师请问
下面for嵌套循环怎么做到与上面的一样
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637