
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 10476 Articles for Python

554 Views
In this example, we will count Negative Numbers in a Column-Wise and Row-Wise Sorted Matrix. At first, we will create a matrix − mat = [ [-1, 3, 5, 7], [-6, -3, 1, 4], [-5, -1, -10, 12] ] Pass the matrix to a custom function and use nested for loop − def negativeFunc(mat, r, c): count = 0 for i in range(r): for j in range(c): if mat[i][j]

3K+ Views
In this article, we are going to learn about the logical operators on strings in Python. The logical operators such as and, or, and not are used to combine the conditional statements and control the flow of logic. While they are commonly used with the Boolean values, they can also be used with strings and other non-Boolean types.Logical Operators on String in Python? In Python the non-empty strings are considered as true, and the Empty strings ("") are considered as false. When the logical operators are applied to the strings, they do not return Boolean values directly; instead, they return one ... Read More

5K+ Views
Permutations refer to arranging the members of a set into different sequences. if the set is already ordered, rearranging (reordering) its elements. If a set has n elements, the total number of permutations is n! (factorial of n) Some common approaches we can use to generate all permutations of a set in Python are as follows. Using a for loop Using itertools.permutations() function. ... Read More

6K+ Views
In this article we are going to learn about class or static variables on python. The class variables or static variables that are used to share across all the instances of a class. Unlike the instance variables which are specific to each object, Class variables maintain the common value for all the objects of the class. They are defined within the class but outside any instance methods, making them accessible to all the instances. These variables are used when we want to have a single shared state or value among all instance. Example 1 Let's look ... Read More

1K+ Views
The Python division operator is used to divide two integer values and return a quotient. To perform a division operation, we use the / symbol. For example, 16 divided by 4 is written as 16 / 4, which returns 4 as the quotient. Here, 16 is known as divident and 4 is known as divisor. The division operator is one of the arithmetic operator. When we divide an integer by zero, it will raise a ZeroDivisionError exception in Python. For example, if we try to divide 55 by 0 using 55 / 0, it will raise a ZeroDivisionError exception. Types ... Read More

3K+ Views
Both str() and repr() methods in python are used for string representation of a string. Though they both seem to serve the same puppose, there is a little difference between them.Have you ever noticed what happens when you call a python built-in function str(x) where x is any object you want? The return value of str(x) depends on two methods: __str__ being the default choice and __repr__ as a fallback.Let’s first see what python docs says about them −>>> help(str) Help on class str in module builtins: class str(object) | str(object='') -> str | str(bytes_or_buffer[, encoding[, errors]]) -> str ... Read More

5K+ Views
In Python, to get values from users, use the input(). This works the same as scanf() in C language. Input multiple values from a user in a single line using input() To input multiple values in one line, use the input() method − x, y, z = input(), input(), input() Let’s say the user entered 5, 10, 15. Now, you can display them one by one − print(x) print(y) print(z) Output 5 10 15 From above output, you can see, we are able to give values to three variables in one line. To avoid using multiple input() methods(depends on ... Read More

1K+ Views
There is always a debate in the coding community on which python version was the best one to learn: Python 2.x or Python 3.x.Below are key differences between pyton 2.x and python 3.x1. The print functionIn python 2.x, “print” is treated as a statement and python 3.x explicitly treats “print” as a function. This means we need to pass the items inside your print to the function parentheses in the standard way otherwise you will get a syntax error.#Python 2.7 print 'Python', python_version() print 'Hello, World!' print('Hello, World!') print "text", ; print 'some more text here'OutputPython 2.7.6 Hello, World! ... Read More

1K+ Views
If you have done little-bit of programming in python, you have seen the word “**args” and “**kwargs” in python functions. But what exactly they are?The * and ** operators did different operations which are complementary to each other depending on where we are using them.So when we are using them in method definition, like -def __init__(self, *args, **kwargs): passAbove operation is called ‘packing” as it pack all the arguments into one single variable that this method call receives into a tuple called args. We can use name other than args, but args is the most common and pythonic way of ... Read More

3K+ Views
From doing simple to complex mathematical operations(like trigonometric, logarithmic operations etc) in python we may need to use the math() module.The python math module is used to access mathematical functions. All methods of math() function are used for integer or real type objects but not for complex numbers.To use this function, we need to import it in our codeimport mathConstantsWe use these constants for calculation in python -ConstantsDescriptionsPiReturn the value of pi: 3.141592EReturn the value of natural base e. e is 0.718282tauReturns the value of tau. tau = 6.283185infReturns the infinitenanNot a number typeNumbers and Numeric RepresentationPython provides different functions ... Read More