OBJ[XXX] = "XX" This action triggers the __setitem__ method of the object.del obj["xxx"] This action triggers the __delitem__ method of the object.obj["XXX"] triggers the __getitem__ method of the object.Class Foo:def __init__ (self,name):Self.name=namedef __getitem__ (self, item):Print (Self.__dict__[item])def __setitem__ (self, Key, value):Self.__dict__[key]=valuedef __delitem__ (self, key):Print (' del Obj[key], I execute ')Self.__dict__.pop (Key)def __delattr__ (self, item):Print (' del obj.
Here is a question I wrote!!! Under the closed principle of satisfying function, the indefinite length parameter of the printing function is realized, and the execution time of the printing function is implemented.Who can who can implement the following print function call method???Import TimedefOuter (func):defInner (*args,**Kwargs): Start=time.time ()Print("*****") func (*args,**Kwargs) Time.sleep (0.5) Stop=time.time ()Print(stop-start)Print(*args,**Kwargs)returnInner@outerdefF (A, B):Print("
not given are used by default parameters and are the same object for the same memory address. 11, [36,5,12,9,21] how to sort?A = [36,5,12,9,21]a.sort ()12. Please answer the following questions:def func (A,b,c=0,*args,**kwargs): What is the role of Pass*args,**kwargs?You can use *args and **kwargs to pass variable parameters when the parameters of the function are not deterministic. *args stores variable positional parameters, it receives any number of parameters and passes them as tuples to
Save some of Python's most common interview questions here, but you can also do it in other languages!1. List to go to heavy1 """2 There is a list of [11, 2, 3, 3, 7, 9, 11, 2, 3], to remove the weight and keep the original order.3 """4 5L1 = [11, 2, 3, 3, 7, 9, 11, 2, 3]6RET =list (set (L1))7 Print(ret)8Ret.sort (Key=l1.index)#Sort by the index of the value in L19 Print(ret)Ten One AL2 = [ -{"name":"Alex"," Age": 36}, -{"name":"Goldboss"," Age": 30}, the{"name":"Xiaoyima"," Age": 18} - ] - #h
Hello"- Enter a description :> input data has multiple groups, one row for each group, including a sentence ( sentence length is less than three characters )- Output Description :> for each Test example, it is required to output sentences that are formed after the word reversal in the sentence- Example 1:```- InputHello Xiao mi- OutputMi Xiao Hello4. # (2017- Good future - written programming questions )-- practice- Title Description :enter two strings, removing all the characters from the sec
):Print('human beings all need work ... ') obj= Person ("Alex","Mans")Print(obj.__dict__)#Check Object Space PropertiesObj.name ="Taibai" #change of Object space propertyObj.hobby ="Play" #increment of object space PropertiesdelObj.sex#Delete the sex attribute of the object spacePrint(Obj.animal)#Object Space View properties in class spaceObj.work ()#methods for manipulating class spaces with objectsclass namespaces and Object namespaces1. Why object space can invoke properties and method
。。‘)for i in range(10): t=threading.Thread(target=run) t.setDaemon(True) #设置子线程为一个守护进程 t.start() print(‘over‘)#主线程结束后,子线程就结束了,run函数不会执行Lockimport threadingfrom threading import Locknum = 0Lock = Lock()def run(): global num lock.acquire() #加锁 num+=1 lock.release() #解锁 with lock: #自动加解锁 num+=1for i in range(100): t=threading.Thread(target=run) t.start()while threading.active_count()!=1: passprint(num)Thread poolYou can control how many threads are allowed
This article is written based on the Python3 crawler, the circle June just touch a day python written by the small demo.Incoming group: 125240963 to get dozens of sets of PDFs Oh!Pre-preparation
python3.x
(Requests,beautifulsoup,lxml)
Import
For leaderboard analysis, the leaderboard matches the song list.NetEase cloud Music exists an interface link to jump to the correct MP3 link
Http://music.163.com/song/medi
not speak here):1 r = Filter (lambda u:a.index (u)% 2 = = 1, a) # in order to get the index value of the element in the list,Call List.index (). 2 print (list (r)) # results are: [5, 9, 12] Once you have the element in the even position, use the map function to add 3 to each element:1 s = map (Lambda y:y+3, List (R))2print(list (s)) # results are: [8, 12, 15 ] So we add 3 to the element of the dual position, and here the SUM function is the simplest, and finally the co
First, the difference between python2x and python3x1, python2x source clutter, high repetition rate, python3x source code beautiful concise and clear.2, python2x default use Unicode encoding, only support English numeric special characters; python3x default UTF-8 encoding, support Chinese.Second, operator1, judge the following logical statements True,false.1) 1 > 1 or 3 2) not 2 > 1 and 3 2. Find the values of the following logical statements.1), 8 or 3 and 4 or 2 and 0 or 9 and 72), 0 or 2 and
1. Differences between methods and functions from Import Methodtype,functiontype class A: def func (self):pass== a.funcPrint (Isinstance (a,functiontype))print(isinstance (b,functiontype))Print (Isinstance (a,methodtype))print(isinstance (B,methodtype))2. Generator relateddef test (): For I in range (4): yield idef Add (n,i): return N+ig=test () for n in [1,10]: g= (Add (n,i) for I I n g) Print (List (g))def Test (): for in range (4): yield idef Add (n,i):
variables in the classThe name of the class. Already has a variable name #查询变量名对应的内容The class name. New variable name = variable content #增加一个变量The class name. Existing variable name-new variable content #对类中已有的变量名对应的变量内容进行修改Del class name. already has a variable name #对类中的变量惊醒删除操作3. Class names Call methods (functions) in a classClass name. Method Name () #此处调用方法 (function) need to pass arguments to the function2. At the angle of the objectThis process of the class name + (): The process of in
# function: # 1. Prevent others from adding new attributes to existing instances;# 2. Optimize memory and execution speed; # The essence of optimization: No longer use dictionaries to store instance data, but more compact array structure; # Especially if you need to create a large number of objects; # attached: When inheriting a base class containing the __slot__ attribute, subclasses also define __slot__ to store their own properties . # Otherwise, the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.