Walrus
The Walrus operator(:=) allows the user to create a variable as well as assign a value to it in the middle of an expression.
Traditional way
Python3
review = "good" n = len (review) if n < 10 : print ( "Minimum 10 characters required" ) |
One Liner
Python3
review = "good" if (n: = len (review)) < 10 : print ( "Minimum 10 characters required" ) |
Here, the length of the string review is stored in a variable n which is defined and declared inside the if statement only.
10 Useful Python One Liners That Developers Must Know
Python is known for its easy-to-code and intuitive syntax. And one-liners are like the cherry on the cake which makes Python a more beautiful and beloved programming language. There are numerous features in Python Language and one of its most loved features is its one-liners. Writing Code in Python is already easy compared to other programming languages and using the one-liners makes it more easier and cool. Now let’s see what are these Python one-liners.
Contact Us