Programming Articles - Page 2093 of 3366

URL handling Python modules (urllib)

Pradeep Elance
Updated on 14-Feb-2020 07:42:20

2K+ Views

Python language is used extensively for web programming. When we browser website we use the web address which is also known as URL or uniform resource locator. Python has inbuilt materials which can handle the calls to the URL as well as pass the result that comes out of visiting the URL. In this article we will see a module named as urllib. We will also see the various functions present in this module which help in getting the result from the URL.Installing urllibTo install urllib in the python environment, we use the below command using pip.pip install urllibRunning the ... Read More

Twitter Sentiment Analysis using Python Programming.

Pradeep Elance
Updated on 14-Feb-2020 07:38:20

346 Views

Sentiment Analysis is the process of estimating the sentiment of people who give feedback to certain event either through written text or through oral communication. Of course the oral communication also has to be converted to written text so that it can be analysed through python program. The sentiment expressed by people may be positive or negative. By assigning weightage to the different words in the sentiment text we calculate a numeric value and that gives us a mathematical evaluation of the sentiment.UsefulnessCustomer Fedback − It is vital for business to know the customer’s opinion about product or services. When ... Read More

Python - Deque

Pradeep Elance
Updated on 14-Feb-2020 07:27:43

504 Views

In Python deque is a data structure like stack and queue. It allows append and pop operations from both the ends of the queue. And that makes it different from the rest of the data structures. There are various operations which are listed below that is applicable to deque. In this article we will see the examples on each of those operations. The collections module is used to implement deque.Deque OperationsBelow are some of the useful operations carried out using dequeappend() − This function is used to insert the value in its argument to the right end of deque.appendleft() − ... Read More

Add trailing Zeros to a Python string

Pradeep Elance
Updated on 14-Feb-2020 07:14:37

4K+ Views

As part of data processing activity we sometimes need to append one string with another. In this article we will see how to append dynamic number of zeros to a given string. This can be done by using various string functions as shown in the programs below.Using ljust and lenPython string method ljust() returns the string left justified in a string of length width. Padding is done using the specified fillchar (default is a space). The len() returns the length of the string. We add trailing zeros to the string by manipulating the length of the given string and the ... Read More

@SafeVarargs annotation for private methods in Java 9?

raja
Updated on 21-Feb-2020 12:16:34

379 Views

The @SafeVarargs annotation was introduced in Java 7. This annotation applies to both final and static methods or constructors that take varargs parameters. This annotation used to make sure that a method does not perform unsafe operations on its varargs parameters. Since Java 9, @SafeVarargs annotation also applies to private instance methods.Syntax@SafeVarargs private void methodName(...) {    // some statements }Exampleimport java.util.ArrayList; import java.util.List; public class SafevarargsTest {    @SafeVarargs     // Apply @SafeVarargs to private methods    private void display(List... names) {       for(List name : names) {          System.out.println(name);       }    }    public static void ... Read More

What is the use of underscore keyword in Java 9?

raja
Updated on 13-Feb-2020 10:29:35

2K+ Views

In earlier versions of Java, the underscore ("_") has used as an identifier or to create a variable name. Since Java 9, the underscore character is a reserved keyword and can't be used as an identifier or variable name. If we use a single underscore character as an identifier, the program fails to compile and throws a compile-time error because now it is a keyword and can't be used as a variable name in Java 9 or later versions.Examplepublic class UnderscoreKeywordTest {    public static void main(String args[]) {       int _ = 50       System.out.println(_);   ... Read More

Writing files in the background in Python

Hafeezul Kareem
Updated on 12-Feb-2020 13:01:33

583 Views

In this tutorial, we will learn about the multi-threading in Python. It helps us to perform multiple tasks at a time. Python has a module called threading for multitasking.We see how it works by writing data to a file in the background while calculating the sum of elements in a list. Let's see the steps involved in the program.Import the threading module.Create a class by inheriting threading.Thread class.Write the file code inside the run method in the above class.Initialize the required data.Write the code to calculate the sum of numbers in a list.Example# importing the modules import threading # creating ... Read More

Testing in Python using doctest module

Hafeezul Kareem
Updated on 12-Feb-2020 12:58:40

2K+ Views

We know docstring gives extra information about the function and classes in Python. We can also use it for testing of the functions using the doctest module. The doctest modules execute the code which starts with >>> and compares it against the expected output.Follow the below steps to write a function with doctest.Import the doctest module.Write the function with docstring. Inside the docstring, write the following two lines for testing of the same function.>>>function_name(*args).Expected output.Write the function code.Now, call the doctest.testmod(name=function_name, verbose=True) function for testing. We can't see the test results if the verbose set to False and all tests ... Read More

Sum 2D array in Python using map() function

Hafeezul Kareem
Updated on 12-Feb-2020 12:54:03

5K+ Views

In this tutorial, we are going to find the sum of a 2D array using map function in Python.The map function takes two arguments i.e., function and iterable. It passes every element of the iterable to the function and stores the result in map object. We can covert the map object into an iterable.Let's see how to find the sum of the 2D array using the map function.Initialize the 2D array using lists.Pass the function sum and 2D array to the map function.Find the sum of resultant map object and print it.ExampleSee the code below. Live Demo# initializing the 2D array ... Read More

Can a diamond operator be used with an anonymous inner class in Java 9?

raja
Updated on 21-Feb-2020 12:18:26

186 Views

Yes, we can use the diamond operator with an anonymous inner class since Java 9.The purpose of using a diamond operator is to avoid redundant code and make it more readable by no longer using a generic type on the right side of an expression. The diamond operator used only for normal classes but not for anonymous inner classes in Java 7. If we try to use it for anonymous inner classes, the compiler throws an error.In the below example, we have used a diamond operator with an anonymous inner class.Exampleimport java.util.*; public class DiamondOperatorTest {    public static void main(String args[]) {       String[] str = ... Read More

Advertisements