Colons Required for if, while, def, and class Statements in Python

AmitDiwan
Updated on 20-Sep-2022 10:59:48

790 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

Why Python Doesn't Have a With Statement for Attribute Assignments

AmitDiwan
Updated on 20-Sep-2022 10:59:02

220 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

Why Can't Raw Strings in Python End with a Backslash?

AmitDiwan
Updated on 20-Sep-2022 10:58:04

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

Why is There No Goto in Python

AmitDiwan
Updated on 20-Sep-2022 10:57:19

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

Specify and Enforce an Interface Specification in Python

AmitDiwan
Updated on 20-Sep-2022 10:54:24

164 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

Why Doesn't List.sort() Return the Sorted List in Python

AmitDiwan
Updated on 20-Sep-2022 10:53:24

565 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

Clear Entire Sheet or Specified Range in Excel

Shibanshu Manna
Updated on 20-Sep-2022 07:37:40

539 Views

Do you often encounter too much data and spend a lot of time selecting and clearing Excel sheets? If so, this tutorial will be helpful to you. When analysing elaborative Excel worksheets, removing non-relevant information often makes it easier to study them. This tutorial explains how to clear an entire spreadsheet and a specified range in MS Excel using two simple methods Method 1: How to Clear The Entire Sheet? This is an easy procedure. If you want to clear the entire sheet, you can use a keyboard shortcut or from the corner cell. We learn how to do ... Read More

Check Size of Each Worksheet in a Workbook

Shibanshu Manna
Updated on 20-Sep-2022 07:36:32

6K+ Views

It is commonly known that when you right-click on an Excel file, you can see its properties and size. But what about when you want to know the size of individual worksheets within the file? Accountants and data analysts maintain large Excel workbooks with multiple worksheets. Understanding the file size can help determine the best way to analyze it. Some might want to begin with the heavy worksheet, or some may start with the lighter one. It often turns out that one sheet takes up the majority of the space in the workbook. This tutorial explains how to identify the ... Read More

Check If Time Is Greater or Less Than Specific Time in Excel

Shibanshu Manna
Updated on 20-Sep-2022 07:35:26

36K+ Views

"Lost time is never found again." Many organisations and professionals are looking for the best way to make the most of their time. Microsoft Excel has the necessary tools and functions to measure time quantitatively. Using an example dataset, we will demonstrate how to measure time against a specific time in Excel using two formulas mentioned in the steps. Find out how in the following steps. Method 1: Measuring Time with a Logical Function We use an example of 9 students who had to submit their assignments before 03:30 PM. Their submission time is recorded in the spreadsheet below. In ... Read More

Check If Time Is Between Two Times in Excel

Shibanshu Manna
Updated on 20-Sep-2022 07:34:09

33K+ Views

MS Excel is handy when you need to keep track of your time and make the most of your resources. Suppose you want to find out how long it takes employees to complete an assignment. You can log the times in your spreadsheet and run a simple function to check if resources are being optimised or not. In light of the results, you can highlight which reports were submitted after the deadline. With two formulas, this tutorial demonstrates how to determine whether a specific time is within a particular range. Using the Nested “IF” Function A logical function, ... Read More

Advertisements