
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

786 Views
The colon is required for all these keywords, if, while, def, class, etc in Python to enhance readability. The colon makes it easier for editors with syntax highlighting i.e. they can look for colons to decide when indentation needs to be increased. Let’s see an example of an if statement − if a == b print(a) And, if a == b: print(a) The 2nd example is easier to read, understand and indent. This makes the usage of colon quite popular. The def and if keyword example We have an if statement in ... Read More

218 Views
Python definitely has a with statement. It wraps the execution of a block, calling code on the entrance and exit from the block. Some languages have a construct like the below − with obj: a = 1 total = total + 1 The above a = 1 is equivalent to the following − obj.a = 1 And, total = total + 1 is equivalent to − obj.total = obj.total + 1 Programming Languages use static or dynamic types. Static Type Static refers to the execution of a program where type of object is ... Read More

1K+ Views
The r in r-strings means raw strings. String literals may optionally be prefixed with a letter 'r' or 'R'; such strings are called raw strings and use different rules for interpreting backslash escape sequences. When an 'r' or 'R' prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string. For example, the string literal r"" consists of two characters − a backslash and a lowercase 'n'. String quotes can be escaped with a backslash, but the backslash remains in the string; for example, r""" is ... Read More

12K+ Views
Yes, there is no goto statement in Python. Let us first understand what is a goto in C Language. However, the usage of goto is also discouraged in C. The goto statement in C programming provides an unconditional jump from the 'goto' to a labelled statement in the same function. Following is the syntax − goto label; .. . label: statement; Example Let us now see a C program for goto − #include int main () { int a = 10; LOOP:do { if( a == 15) { /* skip the iteration */ a = a + 1; goto LOOP; } printf("a = %d", a); a++; }while( a

163 Views
Let us first see what is an interface spec. The interface spec is an interface specification for a module provided by programming languages such as C++ and Java. It describes the prototypes for the methods and functions of the module. The abc module The abc module introduced in Python 2.6 to define Abstract Base Classes (ABCs). Use the isinstance() and issubclass() to check whether an instance or a class implements a particular Abstract Base Class. With that, the collections.abc module defines a set of useful ABCs such as Iterable, Container, and MutableMapping. The collections module has classes that derive from ... Read More

558 Views
Example In this example, let’s first see the usage of list.sort() before moving further. Here, we have created a List and sorted in Ascending order using the sort() method − # Creating a List myList = ["Jacob", "Harry", "Mark", "Anthony"] # Displaying the List print("List = ", myList) # Sort the Lists in Ascending Order myList.sort() # Display the sorted List print("Sort (Ascending Order) = ", myList) Output List = ['Jacob', 'Harry', 'Mark', 'Anthony'] Sort (Ascending Order) = ['Anthony', 'Harry', 'Jacob', 'Mark'] Where performance matters more, making a copy of the list just ... Read More

7K+ Views
In Python to display calendar, you need to import calendar module, it provides various functions to handle operations related to calendar, and also includes printing a text calendar for a month . Calendar Module The calendar module in python provides various functions and classes to perform date-related operations. To print a calendar in Python, we import the calendar module, which will import all module classes. Key Features Some of the features provided by Calendar module are as follows: Calendar Functions: To generate HTML or text format ... Read More

19K+ Views
Regular expressions, often known as RegEx, are a string of characters corresponding to letters, words, or character patterns in text strings. It implies that you may use regular expressions to match and retrieve any string pattern from the text. Search and replace procedures benefit from the usage of regular expressions. The most common application is searching for a substring that matches a pattern and substituting something else. What are whitespace characters? "Whitespace" refers to any letter or set of characters representing either horizontal or vertical space. Using regular expressions, the metacharacter “\s” matches whitespace characters in python. Algorithm ... Read More

2K+ Views
Introduction The re-module is what we use in Python for regular expressions. Text searches and more complex text manipulation employ regular expressions. Tools like grep and sed, text editors like vi and emacs, and computer languages like Tcl, Perl, and Python all have built-in regular expression support. The re-module in Python offers functions for matching regular expressions. A regular expression that defines the text we are looking for or modifying is called a pattern. Text literals and metacharacters make up this string. The compile function is used to create the pattern. Raw strings are advised since regular expressions ... Read More

2K+ Views
To understand why dictionary keys must be immutable. Let us related it to hash table. The hash table implementation of dictionaries uses a hash value calculated from the key value to find the key. If let’s say the key was a mutable object, its value could change, and thus its hash could also change. As stated above, since whoever changes the key object can’t tell that it was being used as a dictionary key, it can’t move the entry around in the dictionary. Then, When you try to look up the same object in the dictionary it won’t be ... Read More