AmitDiwan has Published 10744 Articles

Why can’t raw strings (r-strings) end with a backslash in Python?

AmitDiwan

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 ... Read More

Why is there no goto in Python?

AmitDiwan

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. ... Read More

How do you specify and enforce an interface spec in Python?

AmitDiwan

AmitDiwan

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

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 ... Read More

Why doesn’t list.sort() return the sorted list in Python?

AmitDiwan

AmitDiwan

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

562 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) ... Read More

Why must dictionary keys be immutable in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 14:25:30

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 ... Read More

Why isn’t all memory freed when CPython exits?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 14:16:22

680 Views

CPython is the default and most widely used interpreter or implementation of Python. It is the original Python version and understands the code written using python specifications. Python is quite serious about cleaning up memory on exit and does try to destroy every single object, but unfortunately objects referenced from ... Read More

Why can’t Python lambda expressions contain statements?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 14:15:57

1K+ Views

Yes, Python Lambda Expressions cannot contain statements. Before deep diving the reason, let us understand what is a Lambda, its expressions, and statements. The Lambda expressions allow defining anonymous functions. A lambda function is an anonymous function i.e. a function without a name. Let us see the syntax − lambda ... Read More

How do I write a function with output parameters (call by reference) in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 14:15:33

6K+ Views

All parameters (arguments) in the Python language are passed by reference. It means if you change what a parameter refers to within a function, the change also reflects back in the calling function. Achieve this in the following ways − Return a Tuple of the Results Example In this example, ... Read More

How do I program using threads in Python

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:49:08

268 Views

Threads are sometimes called light-weight processes and they do not require much memory overhead; they are cheaper than processes. A thread has a beginning, an execution sequence, and a conclusion. There are two modules which support the usage of threads in Python3 − _thread − Deprecated in Python ... Read More

What’s up with the comma operator’s precedence in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:47:49

727 Views

Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. The comma is not an operator in Python; therefore, the precedence concept doesn’t work here. Before moving further, let us first see the precedence of operators in Python from highest precedence to lowest. ... Read More

Advertisements