Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Python ternary Operator Examples

Python doesn’t have a ternary operator. But, it supports writing an if-else statement in such a way that it works as a Python ternary operator. Why Python doesn’t have a special ternary operator? Many programming languages have ternary operators. But, their main purpose is to reduce the code size by removing simple if-else blocks. Python

Python ternary Operator Examples Read More »

Python Array – 13 Examples

Python doesn’t have explicit array data structure. It’s because we can do the same things with the List. The list contains a collection of items and it supports add/update/delete/search operations. That’s why there is not much use of a separate data structure in Python to support arrays. An array contains items of the same type

Python Array – 13 Examples Read More »

Python Switch Case: 2 Alternative Implementations

Python doesn’t support switch-case statements. There was a proposal to introduce Python switch case statements in PEP-3103 but it was rejected because it doesn’t add too much value. We can easily implement switch-case statements logic using the if-else-elif statements. However, we can implement switch-case like behavior in Python using custom code. Implementing Switch-Case in Python

Python Switch Case: 2 Alternative Implementations Read More »