
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10400 Articles for Python

588 Views
magic methods that allow us to do some pretty neat tricks in object oriented programming. These methods are identified by a two underscores (__) used as prefix and suffix. As example, function as interceptors that are automatically called when certain conditions are met. In python __repr__ is a built-in function used to compute the "official" string representation of an object, while __str__ is a built-in function that computes the "informal" string representations of an object. Example Code Live Demo class String: # magic method to initiate object def __init__(self, string): ... Read More

2K+ Views
In OpenCv module, we can use the function cv2.imread() to read an image. When inputting the image path, the image should be in the working directory or a full path of image should be given. cv2.IMREAD_COLOR − This function loads a color image and any transparency of image will be neglected. It is the default flag. cv2.IMREAD_GRAYSCALE − This function loads image in grayscale mode cv2.IMREAD_UNCHANGED − This function loads image as such including alpha channel Source Image Example import numpy as np import cv2 my_img = cv2.imread('C:/Users/TP/Desktop/poor/poverty_india.jpg', 0) cv2.imshow('image', my_img) k = cv2.waitKey(0) & 0xFF # wait ... Read More

2K+ Views
The basic operations of OpenCV is to draw over images. The ability to add different geometric shapes just like lines, circles and rectangle etc. Often working with image analysis, we want to highlight a portion of the image, for example by adding a rectangle that defines that portion. Also as example an arrow to indicate something. cv2.line() − This function is used to draw line on an image. cv2.rectangle() − This function is used to draw rectangle on an image. cv2.circle() − This function is used to draw circle on an image. cv2.putText() − This function is used to write ... Read More

683 Views
News API is very famous API for searching and fetching news articles from any web site, using this API anyone can fetch top 10 heading line of news from any web site. But using this API, one thing is required which is the API key. Example Code import requests def Topnews(): # BBC news api my_api_key="Api_number” my_url = = " https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=my_api_key" my_open_bbc_page = requests.get(my_url).json() my_article = my_open_bbc_page["articles"] my_results = [] for ar in my_article: ... Read More

2K+ Views
Minkowski distance is a metric in a normed vector space that measures the distance between two or more vectors. This is typically used in machine learning to find distance similarity. The formula to calculate the Minkowski distance is - $$\mathrm{D= \big[\sum_{i=1}^{n}|r_i-s_i|^p\big]^{1/p}}$$ Where, xi and yi: Two points in n-dimensional space p: Parameter that determines the type of distance being calculated. For example, if p=1, it is the Manhattan distance, and if p=2, it represents Euclidean distance. For example, if we consider the following vector's as input - x = (0, ... Read More

324 Views
Here we are using regular expression package for extracting email-id from the URL-text file. Given the URL- text file. Using regular expression package we define the pattern of email-id then use findall() function, using this method to check the text which will match with this pattern. Input text= Please contact us at [email protected] for further information."+\ " You can also give feedback at [email protected]" Output ['[email protected] ', '[email protected]'] Example code import re my_text = "Please contact us at [email protected] for further information."+\ " You can also give feedback at [email protected]" my_emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", ... Read More

3K+ Views
Floating number is a number that has a decimal point and can represent both large and very small values. Binary number is a number expressed in the base-2 numeral system, using 0's and 1's. The conversion of floating-point number to binary representation in Python requires to represent the number in the IEEE 754 format(a set of representation of numerical values and symbols). For example, consider a floating number 9.87, its IEEE 754 32-bit binary representation (1 bit for the sign, 8 bits for exponent, and 23 bits for the significand) is "01000001000111011110101110000101". In this article, we will discuss different ways ... Read More

2K+ Views
In this article, we will discuss different methods used to right rotate a list from the given rotation number. A list has comma-separated values (items) of same type or different type between square brackets. To right rotate a list by n, Python offers many ways such as using slicing, rotate() method of the deque object and others. Let's discuss these ways in detail with examples - myList = [5, 20, 34, 67, 89, 94, 98, 110] The following is the output if we assign n as 4 − 89, 94, 98, 110, 5, 20, 34, 67 Right ... Read More

362 Views
There will be times when we misspell some words when we write something. To overcome this problem, we use the PyEnchant module in Python. This module is used to check the spelling of words and suggest corrections that are misspelled words. It is also used in many popular tasks, including ispell, aspell, and MySpell. It is very flexible in handling multiple dictionaries and multiple languages. For example, if the input is 'prfomnc', then the output returned would be - 'prominence', 'performance', 'preform', 'provence', 'preferment', 'proforma'. PyEnchant Module For Windows users, install the pre-built binary packages using pip - pip ... Read More

925 Views
This is very funny game. In this game no player is needed, it is an automatic game. Here we are using two Python modules numpy and random. In this game the mark on the board is put automatically instead of asking the user to put a mark on the board, and it will display the board after each turn unless a player wins. It returns -1 If the game gets draw. Example code import numpy as np import random from time import sleep # first creates an empty board def my_create_board(): return(np.array([[0, 0, 0], [0, ... Read More