In Python, we can return an object from a function, using the return keyword, just like any other variable. The statements after the return will not be executed. The return keyword cannot be used outside the function. If the function has a return statement without any expression, then the special value None is returned. In the following example, the function returned the sum of two numbers - def Sum(a, b): return a+b my_var1 = 23 my_var2 = 105 result_1 = Sum(my_var1, my_var2) # function call print(result_1) Following is an output of ... Read More
What is Modular Exponentiation? To calculate Modular exponentiation, we need to raise a base to an exponent and then calculate the modulus of the result. This includes 3 integers: base, exponent, and modulo. Following is the syntax of the modular exponentiation in Python - (base**exponent) % modulo For instance, consider (2^5) % 5, which indicates 2 raised to the power of 5, which results in 32; When the modulo operation is performed, it returns the remainder, i.e., 32 % 5 is 3. Modular Exponentiation using Recursive Function A function that calls itself is known as a recursive function. Following is ... Read More
A "word cloud" is a visual representation of text data, where the size of each word indicates its frequency or importance within the dataset. It helps us to identify the most common and important words in a text. It is typically used to describe/denote big data in a word. In this article, we will create a word cloud on the Python programming language, and the data is accessed from Wikipedia. Modules to create a Word Cloud in Python Following are the modules required to create a word cloud in Python : Install wordcloud Before installing the word cloud module, you have ... Read More
In general, we look at some external websites to convert our files to PDF format; instead, we can convert them using Python on our own. In this article, we will understand the steps to convert the HTML (Hyper Text Markup Language) to PDF using Python code. Steps to convert HTML to PDF Following are the steps to convert the HTML file to PDF using Python: Step 1: Installation Download the pdfkit library by running the following command in the command prompt: pip install pdfkit Step 2: Download wkhtmltopdf Following are the steps to download wkhtmltopdf: ... Read More
In Java, an enum is a special class used to represent a group of constants (that cannot be changed, like a final variable), such as Days: SUNDAY, MONDAY, TUESDAY, etc. Following is the syntax to create an Enum class in Java: enum ClassName { VALUE1, VALUE2, VALUE3, // ... VALUEN; } Where, enum is a reserved keyword in Java used to define an enum class, ClassName is the name of the enum, and VALUE1, VALUE2, VALUE3, ..., VALUEN are the ... Read More
Java supports file-handling; it provides various classes that provide various methods to read, write, update, and delete data from files in our local system. A properties file is a simple text file with a ".properties" extension that contains configuration data in the form of key-value pairs. It is mostly used in Java applications to manage settings such as database configuration, application messages, or environment variables. How to read Data from a Properties File in Java? To read data from the properties file, you can use the Properties class in Java. This is a subclass of the Hashtable class and it represents a persistent ... Read More
The threads can communicate with each other through wait(), notify(), and notifyAll() methods in Java. These are the final methods defined in the Object class and can be called only from within a synchronized context. The wait() method causes the current thread to wait until another thread invokes the notify() or notifyAll() methods for that object. These methods will throw an IllegalMonitorStateException if the current thread is not the owner of the object's monitor. The wait() Method In Java, the wait() method of the Object class allows threads to pause their execution and wait for a specific condition to be ... Read More
In Java, an Enum is a class or special datatype that defines a collection of constants. It was introduced in Java version 1.5. When we need a predefined list of values that do not represent numeric or textual data, we can use an Enum class. Enums are constants, which means their fields are implicitly public, static, and final by default. The names of enum constants are written in uppercase letters. Following is the syntax to create an Enum in Java: Enum enumName{ CONST_VALUE1, CONST_VALUE2, CONST_VALUE3....CONST_VALUEN; } Retrieving Name of the Enum Constant The java.lang.Enum class provides various methods ... Read More
What is a Mersenne Number? A Mersenne number is a positive integer that is obtained using the expression M(n)= 2n-1, where 'n' is an integer. If you keep any value of n (e.g., 0, 1, 2, 3) in the above expression, the result will be a Mersenne number. For example, consider n = 2 and calculate the expression 22 - 1. The result is 3, which is a Mersenne number. Not all Mersenne numbers are prime (e.g., 24 - 1 = 15) is a mersenne number, which is not prime. Here are some other examples of Mersenne numbers: ... Read More
Adding two numbers in Python is one of the most basic tasks, where we need to combine their values to get a total. In this article, we will see different ways to add two numbers in Python. Using Arithmetic Operator To add two numerical values in Python, we can use the addition operation, represented by the "+" symbol. It is one of the arithmetic operators in Python that performs the addition operation. Example Here is the basic example that adds the two numbers using the addition operator (+). # Assign values to the variables a = 7 b = ... Read More