Found 33676 Articles for Programming

Precision Handling in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

3K+ Views

Python can handle the precision of floating point numbers using different functions. Most functions for precision handling are defined in the math module. So to use them, at first we have to import the math module, into the current namespace. import math Now we will see some of the functions for precision handling. The trunc() function The trunc() method is used to remove all fractional part from a floating point number. So it returns only the integer part from the number. The ceil() function The ceil() method is used to return the Ceiling value of a ... Read More

Formatted text in Linux Terminal using Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

331 Views

In this section, we will see how to print formatted texts in Linux terminal. By formatting, we can change the text color, style, and some special features. Linux terminal supports some ANSI escape sequences to control the formatting, color and other features. So we have to embed some bytes with the text. So when the terminal is trying to interpret them, those formatting will be effective. The general syntax of ANSI escape sequence is like below − \x1b[A;B;C A is the Text Formatting Style B is the Text Color or Foreground Color C is the Background ... Read More

Reading and Writing to text files in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

2K+ Views

Like other languages, Python provides some inbuilt functions for reading, writing, or accessing files. Python can handle mainly two types of files. The normal text file and the binary files. For the text files, each lines are terminated with a special character '' (It is known as EOL or End Of Line). For the Binary file, there is no line ending character. It saves the data after converting the content into bit stream. In this section we will discuss about the text files. File Accessing Modes Sr.No Modes & Description 1 r It is Read ... Read More

Generate a graph using Dictionary in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

2K+ Views

The graphs can be implemented using Dictionary in Python. In the dictionary, each key will be the vertices, and as value, it holds a list of connected vertices. So the entire structure will look like Adjacency list of a graph G(V, E). We can use the basic dictionary object, but we are using default dict. It has some additional features. It has one additional writable instance variable. We are providing a text file, which contains the number of vertices, number of edges, names of vertices, and the list of edges. For undirected graph, we are providing two edges like ... Read More

Python program to find common elements in three lists using sets

Sumana Challa
Updated on 09-Jun-2025 13:49:15

1K+ Views

List is one of the built-in data types in Python, which is a sequence of comma-separated items, enclosed in square brackets [ ]. For example, consider the following lists as input - list1 = [5, 10, 15, 20, 25] list2 = [2, 5, 6, 7, 10, 15, 18, 20] list3 = [10, 20, 30, 40, 50, 60] We will find the common elements in three lists, and the output returned should be - [10, 20] Following are the ways to find common elements in three lists using Sets in Python - Using set.intersection() The set.intersection() method is used ... Read More

Break a list into chunks of size N in Python

Sumana Challa
Updated on 09-Jun-2025 14:25:31

609 Views

The objective is to break a list into chunks of a specific size (n), that is, splitting a list into sublists where each sublist contains n elements. For example, if the list is [12, 33, 11, 56, 44, 89, 23, 34, 12] and the chunk size is 3. Then the output has to be - [[12, 33, 11], [56, 44, 89], [23, 34, 12]]. To break a list into chunks of size n in Python, we use list comprehensions, Numpy library, slicing and others. Let's discuss all the approaches in detail with examples - Using List Comprehension List comprehension provides ... Read More

Send mail from your Gmail account using Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

17K+ Views

In this article, we will see how we can send email with attachments using Python. To send mail, we do not need any external library. There is a module called SMTPlib, which comes with Python. It uses SMTP (Simple Mail Transfer Protocol) to send the mail. It creates SMTP client session objects for mailing. SMTP needs valid source and destination email ids, and port numbers. The port number varies for different sites. As an example, for google the port is 587. At first we need to import the module to send mail. import smtplib Here we are also ... Read More

Tracking bird migration using Python-3

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

466 Views

In some Research works, Researchers uses GPS modules to track the animal behavior. They can track how they are travelling to different places in different time of a year etc. In this example we use that kind of dataset to get an idea, how Birds are moving in different places. In this dataset there are the location details from GPS module are stored. The complete dataset is in CSV form. In that file, there are different fields. The first one is Bird Id, then date_time, Latitude, longitude and speed. For this Task, we need some modules that can be used ... Read More

Shell Sort program in C#

George John
Updated on 27-Jun-2020 06:24:13

855 Views

Shell Sort allows the exchange of items that are far apart in the array and then reduces the gap between them. This is a sort of generalization of Insertion Sort. Shell Sort is known as such as it was published by Donald Shell at first.A program that demonstrates shell sort in C# is given as follows −Example Live Demousing System; namespace ShellSortDemo {    public class Example {       static void shellSort(int[] arr, int n) {          int i, j, pos, temp;          pos = 3;          while (pos > ... Read More

Simple Chat Room using Python

Samual Sam
Updated on 03-Sep-2020 16:10:11

3K+ Views

In this article we will see how to make a server and client chat room system using Socket Programming with Python.The sockets are the endpoints of any communication channel. These are used to connect the server and client. Sockets are Bi-Directional. In this area, we will setup sockets for each end and setup the chatroom system among different clients through the server. The server side has some ports to connect with client sockets. When a client tries to connect with the same port, then the connection will be established for the chat room.There are basically two parts. The server side ... Read More

Advertisements