What are Higher-Order Components in React?
In this article, you’ll learn about python operator overloading with examples.,,We all know what are operators (+, -, <=). In python, operators work for built in classes, but some operator behaves differently with different types. For example ‘+’ operator can add two numbers and also can concatenate two strings.,,Program:,,,a = 10,b = 20,print (a+b),,,,a = 10,b = 20,print (a+b),Output:,,,,a = "hello ",b = "programmer",print(a+b),,,a = "hello ",b = "programmer",print(a+b),Output:,,“hello programmer”,,So, using any operator to perform different operation that are not usually performed, is known as operator overloading. We can change the behavior of operators using operator overloading.,,Or we can also say that “assigning a different work to an operator is known as operator overloading”.,,To perform operator overloading, there are some magic methods provided by Python. Using these methods we can perform any operation we want on a operator.,,The operators that can be overloaded are as follows:,,Operators Methods,+ __add__(self, other),– __sub__(self, other),* __mul__(self, other),// __floordiv__(self, other),/ __div__(self, other),% __mod__(self, other),** __pow__(self, other[ , modulo]),< __lt__(self, other),<= __le__(self, other),== __eq__(self, other),!= __ne__(self , other),>= __ge__(self, other),,The basic idea to perform the operator overloading in python is to define any of these methods in the class then call them using operators.,,Let’s see an example. Suppose we want to overload ‘+’ operator.,,As mentioned above that we can concatenate two strings and add two numbers with the help of ‘+’ operator but here we’ll perform the addition on two objects of a class named as Test.,,Program:,,,#without operator overloading,class Test: , def __init__(self, value):, self.value = value,,n1 = Test(20),n2 = Test(10),print (n1 + n2),,,,#without operator overloading,class Test: , def __init__(self, value):, self.value = value, ,n1 = Test(20),n2 = Test(10),print (n1 + n2),Output:,,TypeError: unsupported operand type(s) for +: ‘Test’ and ‘Test’,,So there is an error that says that we can’t perform addition to add values of the both the Test class’s objects. So we will define the __add___(self, other) method here to add the values of both the objects.,,Program:,,,#with operator overloading,class Test:, def __init__(self, value):, self.value = value, , def __add__(self, other):, return (self.value + other.value), ,n1 = Test(5),n2 = Test(6),print (n1 + n2),,,#with operator overloading,class Test:, def __init__(self, value):, self.value = value, , def __add__(self, other):, return (self.value + other.value), ,n1 = Test(5),n2 = Test(6),print (n1 + n2),Output:,,,,So what we did in above program is just added a __add__(self, other) method that will be called when we use ‘+’ operator on the objects of the Test class.,,It is not necessary to always perform addition on ‘+’ operator we can do anything we want like we can also subtract object’s values by using operator ‘+’.,,In this way you can achieve operator overloading in python. Comment below if you have any doubts.,,Read more
Here you will learn about difference between cookies and cache i.e. cookies vs cache. Both are downloaded to your computer but they have different purposes. Cookies are download to record your previous activities on a particular website. On other hand Cache are used to store the web-pages in memory so when user visits that webpage again then webpage can be loaded from the memory instead of downloading files from web-server again. Difference between Cookies and Cache Cookies Cache 1. What is Small files downloaded to your computer to track your previous activity. Files downloaded to your computer memory to store the current version of the webpage so next time browser doesn’t need to download all the files again from the internet when we visit that webpage again. 2. Advantages Less memory, no extra burden on server, simple to use and implement. Faster access, save time, save data. 3. Size Can support as large as 4kb, 50 cookies per domain (per website), can support at least 3000 cookies in total. Depend on the limit set by your internet browser. 4. Disadvantages Security risk because of its clean plain text. User can disable cookies, User can delete cookies, Track browsing activities. Sometimes websites loaded from cache can be different from the website on internet. 5. Expires Expires after sometime. Kept in the client’s machine until they are removed manually by the user. Let’s see these differences in detail. What is: Cookies (also known as web-cookie, internet cookie or browser cookie) are small files downloaded to your computer. These files are sent from the website that we’re browsing and downloaded by web browser to our computer. These small files may have the information like which links you’ve been visited, buttons you clicked, your log in information, or the pages were visited in the past. When we’ll visit that website next time then the website will use that information to track our previous activity on their website. It can also remember the information that previously entered into form fields like name, date, birth detail, credit card number etc. On other hand, Cache is nothing but some downloaded files in memory which is used by browsers to access web-pages with high speed. When we open a webpage, the pages and all its files are downloaded as browser’s cache in our computer hard drive. When we visits that webpage again, if the resources and dependencies of that web page are still same as our last visit, then browser will fetch that entire webpage or some files of that webpage from the hard drive instead of downloading it from web server, which will increase the speed of accessing that webpage. It will save our time and data too. It holds the resources like files, audio, video and flash files. Advantages: There are many advantages of cookie like it doesn’t take much memory in our computer and storing the cookies on client-side reduces the burden from the server. Cookies are also easy to use and implement. Whereas, Cache improves the browsing experience by increasing the speed of accessing websites. As previously mentioned that if the resources of that particular website are still same then the browser will fetch that website or some files from the computer’s hard drive. Which will save our time and data too. Size: Cookies can be up to 4KB (4096 Bytes) in size, and a website can send 50 cookies on our computer and the number of total cookies can be at least 3000. On other hand, the size of cache depends on the limit set by browser. You can increase the size to store more temporary files using browser’s settings. Disadvantages: Cookies exists as plain text on the client machine, so it can be a security risk because anyone can open and tamper with cookies. Anyone can disable and delete cookies in Browser’s setting. Whereas, the main disadvantage of loading webpage from cache can be different from the website presented on the web-server, because cache may have the results from your visit on that website. Expires: Cookies after a set time and the time of expiration also depends on the type of cookies. For example – session cookie exists only in temporary memory while the user navigates the website. Web-browsers normally delete session cookies when user closes the browser. Persistent cookie expires on a set time by its creator. On other hand, Cache will not expire until user deletes it by himself or the memory allocated for cache runs out of memory.Read more
In this tutorial you will learn about difference between TCP and UDP. TCP TCP stands for Transmission Control Protocol. This is one of the main protocols of the Internet protocol suite. TCP is a connection – oriented protocol that provides a reliable flow of data communication between two computers. That means from source to destination all information in both ways must be reached. So TCP connection – oriented protocol establishes a communication link between a source port/IP address and a destination port/IP address. The ports are bound together via this link until the connection is terminated and the link is broken. An example of connection – oriented protocol is a telephone conversation. A telephone connection is established, communication takes place and finally connection terminated. UDP UDP stands for User Datagram Protocol. This is connection less protocol. It sends independent packets of data (we call these independent packets as datagrams) from one computer to other computer. But this not guarantees that data arrival. So this is not reliable communication. Those who not require strict reliable communication, and who feels that reliable communication gives more overhead, such place UDP is very useful. One best example where UDP is required is, when a clock server sends the current time to its client when requested. Suppose the packet is missed in way. In reliable communication same packet re-sends again. But here it makes no sense that sending same packet, because it shows wrong time. Here TCP is not required. UDP is required. TCP vs UDP - Difference between TCP and UDP Image Source TCP vs UDP – Difference between TCP and UDP TCP UDP 1) Connection-oriented protocol. 1) Connection-less protocol. 2) Reliable communication. 2) Not reliable communication. 3) TCP implements connection as a stream of bytes form source to destination. 3) UDP sends independent packets called datagrams from source to destination. 4) No loss of data, order of delivery are considerable. 4) Order of delivery, no loss of data are not guaranteed. 5) Reliability is important than speed. 5) Speed is important than reliability. 6) TCP header size is 20 bytes 6) UDP header size is 8 bytes 7) TCP follows 3 – way handshake for connection establishment. 7) No handshake is required, since it is connection less protocol. 8) Since reliable communication is necessary in this, TCP uses error – detection and error – correction mechanisms for erroneous packets. 8) No error – checking, no error – detection. It simply discards the packet if it corrupted. 9) There is acknowledgement for each byte. So we called TCP is a byte – stream protocol. 9) No acknowledgement. 10) Flow control, congestion control happen in TCP 10) No flow control or congestion control. 11) Each byte assigned with a sequence number. 11) No sequence number for packets. 12) Example: making a phone call. 12) Example: Playing online games. 13) TCP is required for such protocols that, HTTP, HTTPs, FTP, SMTP, Telnet etc. 13) UDP is required for such protocols that, DNS, DHCP, SNMP, RIP, VOIP, TFTP etc.Read more