Posts

Python Tuple: Here're 2 Ways to Calculate Sum Easily

Image
Python tuple is nothing but a set of data. It can have an 'n' number of elements. Here, in my example, the tuple has 20 Elements. The below logic helps you to calculate the sum of its 20 Elements easily.  A tuple is simply a set, and it can have both positive and negative Elements. So, don't worry. You can calculate the sum even the tuple has negative numbers. Here are 2 Ways You can calculate Sum Display sum after adding each element Display sum at once   Python Logic: #1 Method - The Print Displays Sum in Vertcle after Adding Each Element my_tuple = (1,20, -30, 50, 10, 11, 6, 7, 22, 88, 10, 20, 565, 121, 211, 5, 2, 18, 20, 21) sum = 0 for index in my_tuple:             sum = sum+ index          print("sum of elements:", sum) Note*** Here the print statement is within the For Loop. You May Also Like: How to Use For Loop  in Python Complete Tutorial Python Logic: #2 Method - The Print Displays Total Sum at once my_tuple = (1,20, -30, 50, 10, 11, 6, 7, 22, 88, 10

Python Dictionary: How to Make Subset Easily

Image
Here's an easy method to make a subset of a  Dictionary in Python. You already know that Dictionary has a format of Key, Value and enclosed in curling bracket. Below are ideas with sample logic and how it works. It is useful for your projects and interviews too. Here is a Dictionary my_first_dict = { 'HP' : 100 'IBM': 200 'NTT' : 300 'ABC' : 400 'GDF' : 500 } I want to make a subset. The values are greater than 100 and less than 400. How can you achieve this? Don't worry you can do this easily. I am sharing logic with you. Here is subset Logic: You Can do it Using Dictionary Comprehension Syntax: sub_set = { key:value for key, value in my_first_dict.items() value >100 and value <400} Result References Python Programming: Using Problem Solving Approach

Python Class: Here is Useful Reason to Pass Self

Image
Here is the top reason to pass the 'self' argument in the Python class function. You already know that the python class has two things. One is function and the other one is members.  Structure of a Class class <name of the class>:  def <function name>(<arguments>):  ...  <members> For example, the employee class having data members name and age and member functions getdata() and putdata() can be defined as below. Every function in the class must have at least one argument, self . The data members are accessed via the self object as they belong to the class and not just the function. Likewise, the putdata() function displays the values of the data members. Notes on Python Class A class definition has functions but can also have other members. The attribute of an object is a data attribute, and the function that belongs to an object is the method. Sample Python Class class employee:  def getdata(self):  self.name=input('Enter name\t:')  self.age=in

Python Abstract Classes to Learn Quickly

Image
Here's the best example of how to understand the abstract classes of python quickly. An abstract class means it is a skeleton. You cannot instantiate abstract classes. For Example: The abstract class name is 'dog' o = dog() It gives an error. Since the ' dog' is an abstract class. I am sharing with you a clear understanding of abstract class. So that you can tell confidently about these classes. The syntax for Abstract Class from abc , import ABC , abstractmethod  class <class name>(ABC): @abstractmethod  def <method name>():  #abstract class definition Python Abstract Class Explanation from abc import ABC, abstractmethod class AbsBaseClass(ABC): def __init__(self): print("Abstract class") @abstractmethod def abMeth(self): pass def conMeth(self): print("I'm a concrete method") class Derived(AbsBaseClass): def abMeth(self): print("I'm redefined") o=Derived() o.abMeth() o.conMeth() References Star Python Certification

10 Kafka Interview Questions That Recently Asked

Image
Here're ten interview questions that were asked during Kafka's interview.  These are useful to update your knowledge. Kafka Interview Questions 1. What is Kafka? Kafka is a framework of Publisher and Subscribe. It reads messages from the Producer and allows them to read by Subscribers. It keeps store all the producer messages in the form of topics (underlying partitions). It also maintains logs. 2. What is a Consumer group? Each consumer is part of some Consumer group. By adding more consumers to a Consumer group, you can balance the load. In general, the Consumer group reads data from the same topic. The number of partitions in a Topic always should be the same as Consumers in a particular CG (consumer group). 3. What is Fault-Tolerance? Each partition is replicated on multiple servers. So, when one partition is failed, the other backup will deliver. So this concept is called Fault-tolerance. 4. Can we decrease the partitions that we created? No, you can't decrease the par

10 Top Tech Mahindra Fresher Interviews Questions

Image
Here're the ten top interview questions asked during fresher interviews. These are general questions and applicable for all B. Tech branches. 10 Interview Questions 1. What is Full-Service Web-hosting? It is a service offered by website hosting companies. So that the site can be accessed via the world wide web. 2. What is meant by Port blocking within LAN? It restricts the users to access services through various ports. The ports are USB, DVD port, Floppy, Removal device ports. 3. What is IDN? It enables people to use Domain names in local languages. 4. Can we call one program (not include) from another program? Yes, you can call. Here not include means external program. 5. How can you sort the elements of an array in descending order? In C++, you can use Array.Reverse(arr); 6. How do I update my DNS records? You can update DNS records in CNAME. Here're more options. 7. How do non-root -bridges decide, which port will affect the root port? In each non-root bridge (CAT2, CAT3, C

Print Dictionary Values Simplified Logic

Image
Here's for loop logic that says how to use Dictionary to get its data. I will present here how to use it as input In for loop. You can also call Dictionary as Map, Hash, or Associative array. How to Print Dictionary Values Simplified With For loop Below is my example. I have created a simple Dictionary called 'store.' Then, I will get its data using for-loop. Here's my previous post Python -  How to Lookup Dictionary By Key . Dictonary Example Store = { "rao" : 1, "srini' : 2} For Loop Logic for key in store:       print (key, store[key]) Laptop batteries can last longer if you charge them up to only 80% instead of the full 100%. - By Lifehack.org Real-Time Result The execution of for loop showed here. It's much simple. Just use the code as I did. You'll get the desired result quickly. References Python for Everybody: Exploring Data in Python 3 SOFT SKILLS for a BIG IMPACT: Banish Self-Doubt, Improve Workplace Ethics