Skip to main content

Posts

Showing posts from August, 2017

Understand the lambda expression python. On Python Hunter

hitman47silent994c4@gmail.com Hello and welcome again. If you are reading this blog then surely you are having some difficulties to understand lambda in python. Well, no need to feel down, it happens to every beginner as i also have been through this. Let's understand the lambda expression.      Anonymous functions can be created with lambda expression, commonly known as lambda functions or anonymous functions.  Lambda expression gives us the facility to write very short function in one expression. Here are some examples that will help you to comprehend the lambda expression. (Just for beginner) NOTE: Every code snippet is tested in python version 3.x Lambda expression without any argument. method = lambda : 1+3 # or any other expression. print(method()) Output:- 4 If you print what type of variable is that print(type(method)) It will print  <class 'function'> Just like that: def me

Understanding the usage of underscore( _ ) of Python for beginner. On Python Hunter

Introduction: Just like you, a newbie in python scripting language, me too was confused about lot of new things in python that are not valid or available in other languages like Java, .Net etc. Just like other things i had seen the use of '_' underscore in python, at beginning level that flabbergasted me for a while.      With some research and practice i have summarised the following usage of '_' underscore in python. Hope you will find it helpful at beginning level. First Usage : Hold the previous output value. When used in interpreter. 1 2 3 4 5 6 7 _ = input () # For example you typed '5' print (_) # This will print '5' print ( int ( _ ) * int ( _ ) ) # This will print '25' print ( int ( _ ) + 10 ) The above will print '15', because last input was "5" and in above   line of code is producing '25' as output but not being handl