python3.7 中并不报错这是为什么,还能正常运行
C:\Users\Administrator>python C:\Users\Administrator>
老师问一下,这个运行
没有结果问一下是啥问题
person(): (name): .name=name (self): (self.name) (): () (): () p1=person() p1.s=p1.fun=types.MethodType(funp1) p1.fun() p1.s=s p1.q=q p1.s() p1.q()
为什么p1.q()会报错
根据结果,感觉这个贪婪和非贪婪没区别啊,刷新运行了几次结果都一样。
import time def writelog(func): try: file=open("log.txt","a",encoding="utf-8") #a就是追加模式 #写入相关数据信息(访问的函数名,访问的时间) file.write(func.__name__) file.write("\t") #添加一个制表符 #写入访问时间 file.write(time.asctime()) file.write("\n") except Exception as e: print(e) finally: file.close() def func1(): writelog(func1) print("我是功能1") def func2(): writelog(func2) print("我是功能2") func1() func2()
老师 代码当中那个func.__name__ 和 time.asctime() 这两个是什么意思 可以解释一下吗
老师您好,这里不应该是先输出创建对象为1之后再结束吗?为什么会这样
视频中说python会每隔一定的时间对对像的引用计数减1,我想问的是只是针对当前引用计数为1的对像去减1,还是对所有对象的引用计数去减1?第二个问题是为什么对循环引用,引用计数会是失效?
这是怎么回事
#pattern = r'.*\ber' #匹配左边界 #pattern = r'.*er\b' #匹配右边界 #s = '123,eroa' #s = '123,oaer' #v = re.match(pattern,s) #print(v) #匹配单词边界\B pattern = r'.*\Ber' #匹配左边界 #pattern = r'.*er\B' #匹配右边界 s = '123,peroa' #s = '123,oaer' v = re.match(pattern,s) print(v)
我不太明白对单词边界的匹配,为什么\b会到er就结束,\B到per也就结束了,不应该是左边界朝后都是的吗
def dictionary_reader(filename): """ :param filename: The type of the filename is string, which means users need to input a string type's filename. :return: a list which contain each word in the file """ words_no_punctuation = [] words_less_than_9 = [] try: # open the file and execute the read operation f = open(filename, 'r') # append the each word speratly into a list words = f.readlines() for word in words: words_no_punctuation.append(word.strip()) for word in words_no_punctuation: if len(word) <= 9: words_less_than_9.append(word) # print(len(words_less_than_9)) # This is the test part of the dictionary_reader # Test passd, if length of list equal to 235887 x = '' for word in words_less_than_9: if len(word) > 9: x = False break else: x = True continue if x == False: print("Not all of the len of word in this list, which is less than 9 characters.") else: print("-----Test passed! All words in this list are less than 9 characters-----") if len(words) == 235887: print("-----Test passed! There are 235887 words in the list!-----") else: print("The len of words is not equal to the len of word in the words.txt.") if isinstance(words_less_than_9, list): print("-----Test pssed! The function dictionary_reader will return the all words which len are less than 9 characters in a list!-----") else: print("The return stuff is not the list type.") return words_less_than_9 except BaseException as e: # print the error information when programme meet error # it is easy to help users matain the programme print(e) finally: # make sure the file stream will be closed in any suitation of programme f.close() def word_lookup(): # read file at first # words is a list, and each elements in the words list is a word. words = dictionary_reader('words.txt') sorted_dictionary = [] longest_words = [] possibility_words = [] for word in words: """ every single word in the words list will be sorted by alphabetical. """ word = word.strip() # ensure every single word in the list is lowercase sorted_dictionary.append("".join(sorted(word)).lower()) print(sorted_dictionary)
words.txt WechatIMG945.png
老师您好,这是我写的的两个函数。在word_lookup里面我尝试把文件里面的每一个单子都变成字母排序,但是控制台输出的第一个单词并不是按字母排序去排序的,请问一下这是为什么?
输出在附件里面传上去了,不知道为什么不能够上传图片,抱歉。
谢谢老师
老师,如果要统计二进制中数字'0'的个数怎么办?
晕乎乎的~
老师,这个具体怎么解决?是路径不对还是方法不对,应该怎么改,谢谢老师
老师,装饰器和闭包的关系是什么呢?装饰器一定要是闭包的写法吗?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637