Posts

Showing posts from July, 2018

Callable in Python

Image
  Code The callable () takes an object as Input and then It returns boolean value as an Output. Now, If the object you are passing is callable then it will return True otherwise it will return False As we all know function is callable like we a function and we can call it anywhere. Example 1: def demo_function_example():        print("Hey I am with in Function") Now if you want to check the above function is callable or not? see the below code sample >>>callable(demo_function_example) Output:  True Similarly for a class Example 2 : class DemoClass:            pass >>>callable( DemoClass) Output: True But if we create one object and test the is it callable or not ? we will get False >>> obj = A() >>> callable(obj) False So, to make the object callable we need to create one __call__ method within that class. See the below code >>> class DemoClass: def __call__(self): print("I am Now Callable") pass >>> obj =

Function in Python

Image
   Code Example Example 1: def full_name():        print("My name is : Kuntal Samanta") full_name() output : My name is : Kuntal Samanta Example 2: def full_name(fn, ln):       print("My name is : ", fn, " ", ln) full_name("Kuntal", "Samanta") output : My name is : Kuntal Samanta Example 3: def full_name(fn="Firstname, ln="Lastname"):       print("My name is : ", fn, " ", ln) full_name() output : My name is : Firstname Lastname full_name("Kuntal", "Samanta") output : My name is : Kuntal Samanta Example 4: def add(x, y):       return  x + y result = add(10, 20) print(result) output: 30 Example 5: def demo(x, y):       return  x, y r1, r2 = demo(10, 20) print(r1, r2) output: 10, 20 Quiz Level 1 Quiz Level 2 Request Me

Break & Continue In Python

Image
  Code Example # Break n = input("Enter Break Number [1-10] : ") print(type(n)) n = int(n) print(type(n)) for i in range(1, 11, 1):     print(i)     if i == n:         break     else:         pass Output: Enter Break Number [1-10] : 7 <class 'str'> <class 'int'> 1 2 3 4 5 6 7 # Continue n = input("Enter Skip Number [1-10] : ") print(type(n)) n = int(n) print(type(n)) for i in range(1, 11, 1):     if i == n:         continue     print(i) Output: Enter Skip Number [1-10] : 4 <class 'str'> <class 'int'> 1 2 3 5 6 7 8 9 10 Enjoy Edge-cutting Technology 😉 Quiz Level 1 Quiz Level 2 Request Me