- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 10784 Articles for Python
2K+ Views
We can print multiple blank lines in python by using the character the number of times we need a blank line. For example, If you need 5 blank lines, you can use −Python 2.x: print "" Python 3.x: print("")You can use features like repetition operator in python to make this easier. For example,Python 2.x: print "" * 5 Python 3.x: print("" * 5)All of these commands will print 5 blank lines on the STDOUT.
159 Views
To use Server-Sent Events in a web application, you would need to add an element to the document.The src attribute of the element should point to an URL that should provide a persistent HTTP connection that sends a data stream containing the events.The URL would point to a PHP, PERL or any Python script that would take care of sending event data consistently.ExampleHere is an example showing application that would expect server time. /* Define event handling logic here */
1K+ Views
In this article, we will show you how to find the HCF (Highest Common Factor) or GCD (Greatest Common Factor) in Python. Below are the various methods to accomplish this task: Using For Loop Using Euclidean Algorithm Using While Loop Using Recursion(Naive method) Handling Negative Numbers in HCF What is H.C.F. or G.C.D? The largest positive integer that perfectly divides the two given numbers is known as the highest common factor (H.C.F.) or greatest common divisor (G.C.D.). Example - The HCF of 12 and 14, is 2. Using For Loop Algorithm (Steps) Following are the Algorithm/steps to be followed to ... Read More
405 Views
An OrderedDict is a dictionary subclass that remembers the order in which its contents are added, supporting the usual dict methods.If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.>>> from collections import OrderedDict >>> d = {'banana': 3, 'apple':4, 'pear': 1, 'mango': 2} >>> od=OrderedDict(d.items()) >>> od OrderedDict([('banana', 3), ('apple', 4), ('pear', 1), ('mango', 2)]) >>> od=OrderedDict(sorted(d.items())) >>> od OrderedDict([('apple', 4), ('banana', 3), ('mango', 2), ('pear', 1)]) >>> t=od.popitem() >>> t ('pear', 1) >>> od=OrderedDict(d.items()) >>> t=od.popitem() >>> t ('mango', 2)
304 Views
In this article, we will explain to you where are operators mapped to magic methods in python. Python Magic methods are special methods that begin and end with double underscores. They are also known as dunder methods. Magic methods are not intended to be invoked directly by you, but rather invocation occurs by the class on a specific action. When you use the + operator to add two numbers, the __add__() method is called internally. Many magic methods in Python are defined by built−in classes. To get the number of magic methods inherited by a class, use the dir() function. ... Read More
351 Views
Python's set object represents built-in set class. Different set operations such as union, intersection, difference and symmetric difference can be performed either by calling corresponding methods or by using operators.Union by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.union(s2) {1, 2, 3, 4, 5, 6, 7, 8} >>> s2.union(s1) {1, 2, 3, 4, 5, 6, 7, 8}Union by | operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1|s2 {1, 2, 3, 4, 5, 6, 7, 8}Intersection by method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.intersection(s2) {4, 5} >>> s2.intersection(s1) {4, 5}Intersection & operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1&s2 {4, 5} >>> s2&s1 {4, 5}Difference method>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1.difference(s2) {1, 2, 3} >>> s2.difference(s1) {8, 6, 7}Difference - operator>>> s1={1,2,3,4,5} >>> s2={4,5,6,7,8} >>> s1-s2 {1, 2, 3} >>> s2-s1 {8, 6, 7}
144 Views
Every class in Python, whether built-in or user defined is inherited from object class. The object class has a number of properties whose name is preceded and followed by double underscores (__). Each of these properties is a wrapper around a method of same name. Such methods are called special or magic methods.The magic methods __lt__(), __gt__(), __eq__(), __ne__(), etc. are overridden in a class to overload == and != operators respectively.
29K+ Views
In this article, we will show you how to perform square root without using a math module in Python. Below are the various methods to accomplish this task: Using exponential operator ** Using Mathematical Logic Using exponential operator ** Without using the math module, the simplest approach to find the square root of a number in Python is to use the built-in exponential operator ** (It is an exponent operator because it calculates the power of the first operand to the power of the second operand). Algorithm (Steps) Following are the Algorithm/steps to be followed to perform the desired ... Read More
2K+ Views
In this article, we will show you how to calculate the square root of a number in Python. Below are the various methods to accomplish this task − Calculating square root using sqrt() Calculating the square root using the pow() function Calculating the square root using the exponent operator Calculating square root using the cmath module What is the square root of a number? The square root of a number is a value when multiplied by itself returns that same number. Example − 5 x 5 = 25, hence the square root of 25 is 5. However -5 ... Read More
23K+ Views
In this article, we will show you how to round up a float number in Python. Round up float number using the round() function The round() function gives a floating point number with a specified number of decimals which is the rounded version of the specified number. The function will return the nearest integer because the default value for the number of decimals is 0. Syntax round(number, digits) Parameters number(required) − a number that should be rounded digits(optional) − up to the number of decimals to be rounded. 0 is the default. Python has an in-built function round() for ... Read More