AmitDiwan has Published 11365 Articles

How do I create static class data and static class methods in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:35:57

2K+ Views

Python includes the concept of static class data and static class methods. The static class data Here, define a class attribute for the static class data. Explicitly use the class name in the assignment, if you want to assign a new value to the attribute − class Demo: ... Read More

How can I organize my Python code to make it easier to change the base class?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:35:18

271 Views

Before learning how to change the base class, let us first understand the concept of base and derived class in Python. We will learn about Base and Derived class using the concept of Inheritance. In multiple inheritance, the features of all the base classes are inherited into the derived class. ... Read More

How do I get int literal attribute instead of SyntaxError in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:32:12

216 Views

To get int literal attribute instead of SyntaxError, use a space or parenthesis. The int literal is a part if Numeric Literals in Python. Numeric Literals also includes the following four different numerical types − int (signed integers) − They are often called just integers or ints, are positive ... Read More

Why does -22 // 10 return -3 in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:30:57

245 Views

In Python, -22//10 returns -3 because of the concept of Floor Division i.e. Double Slash Operator. The // is the Double Slash i.e. Arithmetic Operator. Let us first understand about it. Floor Division in Python The division of operands where the result is the quotient in which the digits after ... Read More

How it is possible to write obfuscated oneliners in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:28:41

258 Views

Yes, it is possible to write obfuscated one-liners in Python using Lambda. Before moving further, let us first understand what are Lambdas in Python. Python Lambda 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 ... Read More

Is there an equivalent of C’s “?:” ternary operator in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:26:25

330 Views

Yes, we can work around C Language’s ternary operator in Python as well i.e. a similar way do exist. Let us first see an example of C Language’s ternary operator − Example #include int main() { int x = 10; int y; ... Read More

My Python program is too slow. How do I speed it up?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 13:09:17

247 Views

If your Python program is too slow, you can follow the below given tips and tricks − Abstraction Avoid excessive abstraction, especially under the form of tiny functions or method. Abstractions tend to create indirections and force the interpreter to work more. If the levels of indirection outweigh the amount ... Read More

Why did changing list ‘y’ also change list ‘x’ in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 12:36:08

139 Views

Example In this article, we will see if you will change a list, let’s say List y will also change list x. For this, let us first see an example with two lists and try to append() and print − x = [] y = x print("Value of y = ... Read More

What is the difference between arguments and parameters in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 12:33:48

1K+ Views

The concept of arguments and parameters are part of Functions in Python. Therefore, before moving further let us learn how to create a function and parameterised function. A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for ... Read More

How can I pass optional or keyword parameters from one function to another in Python?

AmitDiwan

AmitDiwan

Updated on 19-Sep-2022 12:29:10

880 Views

To pass optional or keyword parameters from one function to another, collect the arguments using the * and ** specifiers in the function’s parameter list But, at first, do know what are *args and **args in Python. Let us understand them − Variable-length/ Arbitrary arguments in Python (*args) Example When ... Read More

Advertisements