Posts

Showing posts from February, 2021

#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       ...

#6 Python :- Lists

  Lists:-  In Python programming, a list is created by placing all the items (elements) inside square brackets [], separated by commas. It can have any number of items and they may be of different types (integer, float, string etc.). e.q:-   mylist=[1,2,3,4] Properties:- i) Mutable:- it can be change.             e.q. mylist=[1,2,3,4]                        print(mylist[1])  ---> 2                     mylist[1]=55                       print(mylist) ----> [1,55,3,4] ii) Ordered :- Can do slicing and indexing.          e.q.  mylist=[monu, sonu, madhu, manish]                    print(mylist) -----> Error               mylist=["monu","sonu","madhu","m...

#5 Python :- String

 Strings:-                                Collection of characters inside single quotes or double quotes. In python strings are writing with quotation of single or double commas. Let us look at examples which of the followings are strings or not:- Q:- a) a="Gurpreet Singh"   ----> String       b) a='Gurpreet Singh'   ----> String       c) a= "I'm a string"       ----> String       d) a='I'm a string'         ----> Not a String       e) a='I\'m a string'       ----> String Now we learned to find either given variable is String or not.  Properties of String:-              i) Immutable (it means we can't change the values of string)                 Code:-     ...

#4 Python :- Variables

  What is variable?  Since it we are talking about variable so it can be anything can be a number ,decimal, word or even a line etc. It has no fix value. In simple words, it is like a container which is used for storing different data values. We can understand a variable by example:- e.q.  #Declaring a variable         #Suppose variable are Var1, Var2, Var3             Var1="Gurpreet Singh"            Var2= 50            Var3= 2.5         # We can know the types of variable by using syntax type()              print(type(Var1)) ---> str() . It is string type.            print(type(Var2)) ---> int(). It is integer type.            print(type(Var3)) ---> float().   Now let us move on next step which is  inter-converting ...