Posts

#13 Python :- Functions

 Functions:- There are two types of functions in python :-                     i) Defined function:- These are the functions whose work is already pre-defined .                            e.q.: type() funtion , len() funtion etc.                     ii) Undefined function:- These are the functions whose work is not defined we have to write                                                              some code to execute such functions. Let us see how we can defined a function:- Note:- Defining a functions also means to creating a new function according to our need.      Q:- Make a function to add 2 numbers.       Code:-  de...

#12 Python :- Infinite loop, For loop , Pass, Continue and Break Keywords

 Infinite loop:                     It is the loop which never stops until we stop it. e.q.      while True:                       print("Gurpreet") ------> It prints Gurpreet infinite times. Note:- Sometimes infinite loop started by mistake and sometimes we need to start it. For loop:-         We can use this loop in place of while loop. e.q. print Gurpreet 5 times. Code:- # for loop with range function (start,stop, step arguments)             for i in range(5): # 0 to 4                    print(f"Gurpreet : {i}")   Output: - Gurpreet : 0                 Gurpreet : 1                 Gurpreet : 2                 Gurpreet : 3     ...

#11 Python :- In Keywords , Empty or not, While Loop

  IN Keyword:-         This is used for checking given character or word in a given string. e.q. :-  mystring="Gurpreet"           #if with in            if  'p' in mystring:                     print("Yes present")           else:                    print("Not found")            Output:-    Yes present Empty or not:-                To check weather the given string is empty or not. e.q.1 :-  name="Gurpreet"            if  name:   #true if string is not empty                     print("Yes present")           else:                 ...

#10 Python:-If, Else & Elif

i) If Statement:-                      It is used for executing the coding only when given situation is true/ ii) Else and Elif :-                       These syntax are used in python to print the given statement only when certain conditions are true. Note:- We can use if-else statement in Else syntax which is known as nested if-else.  e.q. Let us take an example if we want to check wheather the given number is greater than hundred or not and if it is greater then print greater or if not then print lesser       Code:-           Var1= int(input())                            Var2= 100                          If Var1>100:                   ...

#9 Python :- Sets, Boolean

Sets:- A set is created by placing all the items (elements) inside curly braces {}, separated by comma, or by using the built-in set() function.  e.q.          myset= {1, 2, 3} or set(1, 2,3) Properties:- i) Immutable:-    We can not change the values of sets . however we can add or remove by using .add()                                    and .remove syntax. ii)Unique:- Every elements inside a set is always unique.                   e.q.    myset= set(1,1,1,2,2,2,2,2,3,3,3,3,3,5,5,5,5,)                          print(myset) -----> {1, 2, 3, 5} iii) Unordered:- We can't do indexing and slicing of set.  Boolean:- It is just checking the given situation is true or false .  e.q.     a) 1>2 ----> False  ...

#8 Python :- Dictionaries

 Dictionary:-                     It is basically key value pair . They are optimized to know the value when the key is known. Creating a dictionary is very simple just placing the elements inside the curly brakets {} separated by commas.               e.q.  mydic= {"monu":"good", "madhu":"lazy", "sonu":"fatty"}           Properties :-          i) Mutable:- It means we can change the values of dictionaries.                       e.q. :-      mydic= {"monu":"good", "madhu":"lazy", "sonu":"fatty"}                                     mydic["monu"] ="cute"                                   print(mydic) ---...

#7 Python:- Tuple

  Tuple:-           It can be created by writing all the element inside parentheses () separated by commas.         e.q :- mytuple=(1,2,3)                  print(mytuple) ------> (1, 2, 3)  Note:- Tuple are faster than list. Properties:-     i) Immutable:- It means we can't assign or change values of tuple.            e.q :-           tup=(1, 5, 9, 2)                               tup[2]=15                              print(tup) ----> Error                    Because we can't change the value inside the tuple since it is immutable.    ii) Ordered:- We can do slicing and indexing       ...