CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Showing posts with label Class 12 CS. Show all posts
Showing posts with label Class 12 CS. Show all posts




Purchase the Class 12 CS CRASH COURSE ebook from here. It is based on the Revised Syllabus of CBSE and Covers UNIT-1 and UNIT-3 of Class 12 CS CBSE Syllabus.

Free Video Lectures are available on the youtube channel cbsecsip, click here to access the free video lectures.


  1. eBook PDF file will be delivered in your email within 15 - 20 minutes of purchase.
  2. This book covers UNIT-1 and UNIT-3, all the topics which are discussed in the Online Youtube Class 12 CS CRASH COURSE of cbsecsip.
  3. Once purchased, the item is not exchangeable or refundable.

What is Plagiarism and How to avoid it


Table of contents

  1. What is Plagiarism?
  2. Acts that involve Plagiarism
  3. How to Avoid Plagiarism

What is Plagiarism?

  • Plagiarism is stealing someone else’s intellectual work (can be an idea, literary work or academic work, etc.) and representing it as your own work without giving credit to the creator or without citing the source of information.
  • Plagiarism is an offense because it involves copyright infringement and not giving the credit to the author.

An act that involves plagiarism

  • Turning in someone else's work as your own
  • Copying words or ideas from someone else without giving credit
  • Failing to put a quotation in quotation marks
  • Giving incorrect information about the source of a quotation
  • Changing words but copying the sentence structure of a source without giving credit.

How to avoid plagiarism

You must give credit whenever you use:
  •  Another person’s idea, opinion, or theory
  • Quotation of another person’s actual spoken or written words
  • Paraphrases of another person’s spoken or written words

Net Etiquettes (Netiquettes)


What is Net Etiquettes (Netiquettes) or Net+etiquetts?

You must be aware of the term etiquette. This means the general behavior you must follow in your daily life. There is a little difference between etiquette and net etiquette. There are some rules that you must obey when you are online and using the Web/internet. These rules are called net etiquette (Netiquettes), Internet etiquettes or Online etiquetts
  • Online etiquette or ‘netiquette’ refers to the dos and don’ts of online communication.
  • You can do Online Communication using Snapchat, Instagram, WhatsApp, etc. These are the most popular online mediums available online.
Now let us discuss net etiquette do's and don'ts and some rules that you should follow while you are using the internet. 

7 Net Etiquettes you should follow

  1. Be respectful.
  2. Be aware of what you are commenting on social media.
  3. Be careful with humor and sarcasm
  4. You should take care of how you are sharing your data and who can see this.
  5. Friend requests and group invites should be checked before you accept them
  6. Take time to have a read of the rules of conduct/ community standards
  7. Be forgiving do not take fight online

Bad net etiquette

  1. Posting inappropriate jokes on social media
  2. Continuously posting messages to get the attention of someone is bad net etiquette.
  3.  Using a photo of another person on your profile
  4. Not respective peoples privacy online
  5. Taking fight online

Digital footprint

Digital Footprints

What is a Digital footprint?

  • A digital footprint is an impact you create on the Web through your online activity, which incorporates browsing, interactions with others, and publication of content. 
  • In other words, it can be considered as the data trail – intentional and unintentional - you leave behind while you surf the Web or Internet. 
  • Digital footprint or digital shadow refers to the trail of data left behind through the utilization of the Web or on digital devices.
  • The digital footprint of any person can have a positive as well as a negative impact on him.

How Digital Footprints are Created-

Find some of the examples of digital footprints:
  • Visiting Websites And Online Shopping
  •  Online Searching 
  •  Posting on Social Media, blogs, etc.
  •  Online Image and Video Upload 
  •  Communicating Online (Ex:- Chat, Email, etc.)
  •  Any activity you perform Online etc.

Types of digital footprints-

Following are the two types of digital footprints:
Active digital footprints:- Active digital footprints are those data trails that a person leaves intentionally on the Web. 
Ex:- Twitter, blog posts, Facebook, social network connections, image and video uploaded on Internet, phone calls, email, and chats are among the ways people create active digital footprints.
Passive digital footprints:- This suggests that a passive footprint would be defined as the unintentional traces of data that an individual creates on the Web.
Ex:- Website visits and actions, searches, and online purchases are among the activities that add passive data traces to a digital footprint.

Positive and Negative Digital Footprints

Positive digital Footprints:- 
That reflects your Positive Personality.
  • Increased opportunity
  • Higher profits
  • Less risk
  • Gentler treatment
Negative digital footprints:- 
Things that reflect your Negative Personality sort of a drunken photo, a silly comment, logging on to an inappropriate website.
  • Fewer Opportunities (like Admission, Job, etc.)
  • Negative Personal Image

How digital footprints can affect you?

  1. Privacy Issues: Digital footprints are a privacy concern because they're a group of traceable actions, contributions, and concepts shared by users. They are often tracked and may allow internet users to find out about human actions.
  2. Cyber Vetting: where interviewers could research about the applicants before the interview based on their online activities on the Web.
  3. Target advertisement: It is used by marketers so as to seek out what products a user is curious about or to inspire ones' interest during a certain product that supported similar interests.
  4. Less/More Opportunities depends upon your Positive/Negative Digital Footprints.

How can you manage your digital footprint?

Though it is not possible to fully hide your digital footprints, you can follow some of the given techniques to manage your digital footprints.
  1. You can search your name on different search engines and they provide you facilities where you can set up an alert for future notifications when your name searched online
  2. Have different email addresses, so professional and private accounts aren't automatically related to each other
  3. You can change privacy settings on social media accounts where you do not make more things public. But you should not trust them completely because your data is still with those platforms.
  4. Exercise caution altogether our activities, and refrain from oversharing

Built Positive Digital Footprints-

Since it is hard to not have a digital footprint, it is in one’s best interest to create a positive one.

It is beneficial for you !!


Cyber Law IT ACT 2000


What is cyber Law?

  • Cyber law, also known as cybercrime law, is legislation focused on the acceptable behavioral use of technology including computer hardware and software, the internet, and networks.
  • Cyber law helps protect users from harm by enabling the investigation and prosecution of online criminal activity.
  • It applies to the actions of individuals, groups, the public, government, and private organizations.

Overview of Indian IT ACT

  • The Information Technology Act, 2000 (also known as ITA-2000, or the IT Act) is an Act of the Indian Parliament notified on 17 October 2000. It is the primary law in India dealing with cybercrime and electronic commerce.
  • A major amendment was made in 2008 and now it is called the IT (Amendment) Act 2008.

Some Suggested questions that may be asked in board examination Class 12 CS/IP

  1. What is Cyber Crime? Write the act that deals with it.
  2. What is IT Act, 2000? Write down 2 salient features of IT Act, 2000.
  3. Difference between Cyber Crime and Cyber Law.

IPR (Intellectual Property Rights)


What is IPR?

  • If a person creates something by himself he posses the right on it, this right is called Intellectual property rights (IPR).
  • IPR gives the right to the creator over the use of his/her creation for a certain period of time.
  • Intellectual property rights can be obtained at the national level/regional level.

Types Of IPR -

The most well-known types are -
  1. Copyrights
  2. Patents
  3. Trademarks
  4. Trade Secrets
The intellectual property right encourages the creation of a wide variety of intellectual goods. To achieve this, the law gives people and businesses property rights to the information and intellectual goods they create, usually for a limited period of time.

Wat Is Copyrights?

  • Copyright (or author’s right) is a legal term, it is used to describe the rights that creators have over their artistic and literary creation. 
  • Copyright is automatic; once you create something, it is yours. However, if you want to file a lawsuit against the infringement of your copyrighted work, then registration of your copyright will be necessary.
  • Works covered by copyright range from books, music, paintings, sculpture, and films, to computer programs, databases, advertisements, maps, and technical drawings.
  • Copyright protection extends only to expressions, and not to ideas, procedures, methods of operation, or mathematical concepts as such. 
  • Typically, the public law duration of a copyright expires 50 to 100 years after the creator dies, depending on the jurisdiction.
  • Copyright may or may not be available for a number of objects such as titles, slogans, or logos, depending on whether they contain sufficient authorship.
  • In the majority of countries, and according to the Berne Convention, copyright protection is obtained automatically without the need for registration or other formalities.

What are Patents?

  • A patent is a type of limited-duration protection that can be used to protect inventions (or discoveries) that are new, non-obvious, and useful, such a new process, the machine, article of manufacture, or composition of matter.
  • When a property owner holds a patent, others are prevented, under law, from offering for sale, making, or using the product.
  • A patent is an exclusive right granted for an invention, which is a product or a process that provides, in general, a new way of doing something, or offers a new technical solution to a problem. 
  • To get a patent, technical information about the invention must be disclosed to the public in a patent application.
  • Kind of protection: Patent protection means that the invention cannot be commercially made, used, distributed, imported, or sold by others without the patent owner's consent.
  • The protection is granted for a limited period, generally 20 years from the filing date of the application.

What Are Trademarks?

  • A trademark is a sign capable of distinguishing the goods or services of one enterprise from those of other enterprises. Trademarks are protected by intellectual property rights.
  • At the national/regional level, trademark protection can be obtained through registration, by filing an application for registration with the national/regional trademark office and paying the required fees.
  • The term of trademark registration can vary but is usually ten years.

What Is Trade Secrets -

  • Trade secrets refer to specific, private information that is important to a business because it gives the business a competitive advantage in its marketplace. Trade secrets are intellectual property (IP) rights on confidential information that may be sold or licensed.
  • Trade secrets are not made public, unlike patents, they do not provide “defensive” protection, as being prior art.
  • Trade secrets are protected without official registration; however, an owner of a trade secret whose rights are breached–i.e. someone steals their trade secret–may ask a court to ask against that individual and prevent them from using the trade secret.
  • kind of information is protected by trade secret: 
  • recipes for certain foods and beverages (like coca-cola or Sprite), new inventions, software, processes, even different marketing strategies. , technical information, such as information concerning manufacturing processes, pharmaceutical test data, designs and drawings of computer programs, distribution methods, list of suppliers and clients, and advertising strategies, financial information, formulas and recipes, and source codes.
  • A trade secret owner, however, cannot stop others from using the same technical or commercial information, if they acquired or developed such information independently by themselves through their own R&D, reverse engineering or marketing analysis, etc. 



order by


When you use the SELECT statement to query data from a table, the result set is not ordered. It means that the rows in the result set can be in any order.

To sort the result set, you add the ORDER BY clause to the SELECT statement. 
The SQL ORDER BY clause is used to sort the records in the result set for a SELECT statement.

The syntax for using ORDER BY -:

SELECT expressions
FROM tables
[WHERE conditions]

ASC –:
 Ascending order by COLUMNS [Default]
DESC – :
Descending order by COLUMNS

Note -:

ORDER BY clause is always evaluated after the FROM and SELECT clause.



The GROUP BY statement in SQL is used to arrange data into groups with the help of some functions. GROUP BY statement is used to retrieve grouped records based on one or more columns.

The aggregate function on SELECT Statement can be used with the GROUP BY Statement.
Aggregate Functions : AVG(),COUNT(),MAX(),MIN(),SUM().

The syntax for GROUP BY Statement in SQL -:


Description MySQL GROUP BY -:

The GROUP BY clause combines all those records (Rows) that have identical values in a particular field (Column) or a group of fields.
This grouping results in one summary record per group.

If you want to total salary for all employees then we used the SUM function and you will get a sum of the total salary.
group by

If you want to total salary department wise like D1 or D2 then we have used GROUP BY.
group by MYSQL

Now you have also used the SUM function and using GROUP BY  tHen you will get the department-wise total salary  You can see all D1 and D2 columns combine in one row.
group by MYSQL

GROUP BY(Nested Grouping) using more than one column -

If you want to GROUP BY using more than one column, you can give all columns by using comma separation.  

Syntex -

SELECT Col1, Col2,AGG_FUN(Col3)
[WHERE <Condition>]
GROUP BY Col1, Col2 ;

group by MYSQL Nested grouping

GROUP BY Condition -

The GROUP BY clause is used with Aggregate Functions.
 All the fields (Columns) other than used in aggregate function should be put in GROUP BY clause.

Syntex -

SELECT AGG_FUN(Col1), Col2, Col3
WHERE <Condition>
GROUP BY Col2, Col3;




Hope you are doing great. I have prepared a question-wise solution for cbse class 12 informatics practices sample question paper 2020-21. I have also discussed cbse class 12 informatics practices question paper pattern 2020. To download the question paper click here.

To check the video you can click on the below-given link. After going to the video you will find time in the description of the video where you can click to go to any question. 

Solution for Sample Question Paper - 2020-21

Data Structures in Python (List / Stack / Queue)

Python MySQL Connector - Download, Install and Use with Examples

Python Mysql connector

When you want to create a real-life application it is required to interact with Database through your program. This can be done through an interface, which provides you with the facility to connect to Database directly through your Python program. As per class 12 CBSE computer science, it is required that a student must know the python and MySQL connection for the project creation.


Python and MySQL both should be installed on your computer.
  • To know how to install Python: Click Here 
  • To know how to install MySQL watch the following Video:
After completing the above two steps follow below-given 6 steps to connect your python program with MySQL and start working on it:

STEP-1: Start Python 

The First step is to start Python. Create a ".py" file in which you want to write the python code for MySQL connection.

STEP-2: install and import mysql-connector

  • The next step is to install mysql-connectormysql-connector is available for Python that is used for connecting the python program with the MySQL Database. 
  • This connector can be installed in python using the following command (run it in cmd):
    pip install mysql-connector
  • If you are facing any error while using this command click here to resolve your environment Path related error. After that, you will not face any problem.
  • After installing the mysql-connector, import it in your program by using the following command: 
    import mysql.connector
    import mysql.connector as sql

STEP-3: Connect Python with MySQL database using connect()

  • connect() function is used to make the connection from python to MySQL and returns a connection object.
  • It is available inside mysql.connector module. Hence to use this function we have to import mysql.connector.
  • Prototype of connect( ) Function:
    <conn_obj> = <mysql.connector>.connect(host="localhost", user="yourusername", password="yourpassword", database ="test“)
  • You can check for successful connection using is_connected( ) Function with connected Object.
    if <conn_object>.is_connected()==False:
        print("Not Conneted")

STEP-4: Create a Cursor instance using cursor()

A Database Cursor is a special control structure that facilitates the row by row processing of records in the result set. 
<cursor_obj> = <conn_obj>.cursor()

STEP-5: Execute SQL Query by Using execute( ) Function

Now you can execute MySQL Queries using execute( ) Function with cursor object as per following syntax:
<cursor_obj>.execute(<sql query string>)

The retrieved record will be available in cursor Object.

STEP-6: Close the Connection

Use the following command to close the connection:

Full code for Python-MySQL Connection

##MYSQL connection with python 
import mysql.connector as sql
con = sql.connect(host='',user='root',passwd='password')
if con.is_connected() == True:
    mycursor = con.cursor()
    mycursor.execute("create database student")
    mycursor.execute("use student")
    mycursor.execute("create table xiicom (name varchar(20))")
    for i in range(5):
        name = input("Enter a Name:")
        s3 = "insert into xiicom values ('{}')".format(name)
    print("Not Connected")

Types of Formal Arguments in Python Functions (Class 12 Computer Science)

Types of Formal Arguments

Python Function can have two types of Arguments / Parameters, First is Actual Arguments and Second is Formal Arguments. In this post I have discussed different types of Formal Arguments. 

Types of formal arguments in Python Functions

Variables that we use in function definition to receive the values coming from function call, is called Formal Arguments. Sending the arguments from Function Call to Function Definition is called argument passing in python. There are 4 different types of formal arguments as shown below in the diagram. 
Types of Formal Arguments
Types of Formal Arguments

Following are the different ways of passing arguments to a function in Python:

  1. Positional arguments (Required arguments)
  2. When the function call statement matches the number and order of arguments as defined in the function definition, this is called positional argument.

    In the below example square(x) is taking one argument, here 'x' is an formal argument. So, at the time of function call we have to pass one argument that will be copied to 'x'.

    This example will give error because we are not passing any parameter at line number 6.   
    1. #error
    3. def square(x):
    4.     z=x*x
    5.     return z
    6. r=square()
    7. print(r)

    To remove this error we must pass an argument at line number 6. This is called a required argument, because without it the program will not execute.
    These are also called Positional Arguments, because if we have more than one argument in function, then the formal arguments receive the values in the same order in which they are passed at the time of function call.

    def square(x):
       return z

  3. Default arguments 
  4. Sometime as a programmer if you want to give default values for some of the arguments, then it can be don with the help of Default Arguments. This will assumes a default value if a value is not provided to argument.

    1. def sum(x=3,y=4):
    2.    z=x+y
    3.    return z
    4. r=sum()
    5. print(r)    #Output: 7
    6. r=sum(x=4)
    7. print(r)    #Output: 8
    8. r=sum(y=45)
    9. print(r)    #Output: 48
    #default value of x and y is being used when it is not passed

    In the above given example you can understand the Default Arguments very clearly.
    • At line number 4 I have called sum( ) function without any argument. So, both the default values of 'x' and 'y' taken by the function sum( ) and the output is coming 7(x=3, y=4).
    • At line number 6 I have called sum( x=4 ) with parameter 'x' only. For 'y' the default value will be taken i.e. 4. So the out will come 8.
    • At line number 8 I have called the function sum( y=45 ) with parameter 'y' only. For 'x' the default value 3 will be taken, and the result will be 48.  

  5. Keyword Argument
  6. In some cases when we know the function and it's parameters name too, but we don't know the order in which they are written in function definition. So, it will be very difficult to pass the values to those parameters from function call.

    In this case the positional parameters will not work, because we don't know the exact order of parameters. 

    To pass the parameters in this case we use Keyword Argument. In this case the caller identifies the arguments by the parameter name. Since we know the parameters name, so we case provide them the values in any sequence or order.

    1. def fun( name, age ):
    2.     print ("Name: ", name)
    3.     print ("Age ", age)
    4.     return
    5. # Now you can call function
    6. fun( age=15, name="mohak" )
    7. # value 15 and mohak is being passed to relevant
    8. # argument based on keyword used for them. 

    In the above case at line number 6 we are calling the function fun( age=15, name="mohak" ), but our function definition at line number 1 fun( name, age ) do not have the same order of argument as it is passed at line number 6. 

    In this case the parameters will be passed as keyword arguments. We can give our parameters in any order but the name of parameters should be specified at the time of function call as we are doing at line number 6. 

  7. Variable-length arguments
  8. Till now we have seen all the types of arguments. If you have gone through all the above types of arguments, you must have a question that how do you pass variable length arguments in python? 

    That means in some cases as a programmer you do not know the exact number and types of arguments that is required to be passes when you call the function. In this case you have to use variable length arguments

    By using this you can receive multiple values with single argument name. Also you can call function multiple times with different arguments. The following code explains the variable length arguments:

    1.  def sum( *vartuple):
    2.      s=0
    3.      for var in vartuple:
    4.          s=s+int(var)
    5.      return s
    6.  r=sum( 70, 60, 50 )
    7.  print(r)
    8.  r=sum(4,5)
    9.  print(r)
    10. #now the above function sum() can sum n number of values

    You can understand the use of variable length arguments by the above example. At line number 1 I have defined a function sum( *vartuple) here *vartuple is a variable length argument. vartuple can receive any number of arguments passed at the time of function call as tuple data type.


    • You can also pass variable length keyword arguments you can receive it in **kwarg variable in function definition.
    • kwarg then will receive the data in the form of dictionary.
    • You must notice that for positional arguments I have used single (*) and for keyworded arguments I have used two stars (**).

Using multiple argument types together

Till now we have discussed 4 different types of arguments. Out of four, default argument is used at the time of function definition, we pass other three arguments at the time of function call.

Let's discuss what will be the order of parameters in a function, if we use multiple argument type's together.

Order of these three different Types of Arguments: 
  1. Positional arguments
  2. Keyword arguments
  3. Variable length argument
First All the Positional arguments then all keyworded arguments at the end Variable length argument should come.

Now we will try to understand it with the help on an example. In the below given function prin and cc are positional argument (required argument) and time and rate are default argumentsConsider the following function:

def Interest( prin, cc, time = 2, rate = 0.09):
      return prin * time * rate

Look at the following function call statements: (Green - Correct, Red - Wrong)

1. Interest(prin = 3000, cc = 5)
2. Interest(rate = 0.12, prin = 5000, cc = 4)
3. Interest(cc = 4, rate = 0.12, prin = 5000)
4. Interest(5000, 3, rate = 0.05)

5. Interest(rate = 0.05, 5000, 3)
6. Interest(5000, principal = 300, cc = 2)
7. Interest(500, time = 2, rate = 0.05)

All the function calls in green are Correct, and all the function call in red are Wrong. 

  1. In the first three function call statement, all the parameters are keyword arguments. We are passing print and cc other two arguments time and rate will be taken by default.  Hence this function call is correct.
  2. In Second call also all the parameters are keyword arguments. Only time is not given, its value will be taken with default parameter. So, this will also a correct function call.
  3. In third case, all the parameters are keyword argument so the order of them does not matter. Value of time parameter will be taken by using default parameter.
  4. In fourth case, there are positional arguments and keyword arguments. Now the order matters. Since all the positional arguments are coming before keyword arguments, this is a correct function calling. 5000 and 3 will be assigned to prin and cc respectively. Value of time will be taken using default value.
  5. Fifth case is wrong because order of parameters are not following. Hence it is wrong function calling.
  6. Since prin and cc are positional argument (required argument), its value must be given at the time of function call. In fifth case value of prin is missing, instead of it principal is given which is wrong parameter name. Hence it is wrong function calling. 
  7. In seventh case, 500 will be assigned to prin. Now one positional argument cc is missing. Hence it is wrong function calling.  

What are the different types of actual arguments in function?

Till now we have discussed different types of Formal arguments. Actual Parameters / arguments are given at the time of function definition. Both actual and formal arguments are related to each other. That is way we can call a function using four different types of arguments and we can receive the arguments in four different ways.   

Types of Arguments / Parameters in Python Functions (Class 12 Computer Science)

Types of Arguments / Parameters in Python Functions


In Python Functions, we define Functions by using the def keyword. After writing def keyword we have to provide function name, it will have parenthesis after it. This may contain Parameter / Arguments.
def square( <Parameters> ):
    <function body>    

square ( <argument> )

In the above example, you can understand where we have to provide parameters in Python Functions. Square is a function and after it we have to give small brackets that notifies this is a function, inside these brackets we have to provide Parameters. 
We can provide various parameters by separating them with comma. ex:- Parameter1, Parameter2,...., etc.

Difference between argument and parameter in Python Function 

Before starting with the Types of Arguments / Parameters in Python Functions let us discuss what the difference between Argument and Parameter and what is the purpose of Arguments and Parameters.

So, as the sample code snipped is depicting, the variable in function or method definition is called Parameter.  The actual values that we pass at the time of function call are called Arguments

But the interesting thing is that we can use these name interchangeably. So, in this article and the upcoming articles, I will use these name interchangeably.

How many parameters can a function have in Python?

Now you must have the question of how many parameters can function have? So the answer is 253. The maximum number of Arguments and their Corresponding Parameters is 253.

How do you pass multiple parameters in Python?

As we have discussed that python allows you to pass multiple arguments to a function, the question arises that how to pass multiple arguments? So, there are different types of arguments in Python using which you can accomplish this task. 

Types of arguments / parameters

There are two types of arguments, one that is used with function definition another that is used at the time of function call:

def square( x ):  # x is Formal Argument
    z = x * x
    return z
r = square( 5 )   # 5 is Actual Argument


1. Actual Arguments / Parameters-:

Parameters that are used during a function call is called Actual Argument. As per the programing example given above '5' is an actual argument, because we are giving it at the time of function call.  

2. Formal Arguments / Parameters-:

Formal parameters are those that are used in the function definition and a function declaration. As per the example given above 'x' is the Formal Argument. It will get the value from the function call. So, the '5' will be assigned to 'x', when the function square(5) is called.

Types of formal arguments

There are 4 types of formal arguments.
  • Positional Arguments (Required arguments): When the position of the parameter in function definition matches with the number and order of the arguments in the function call. Then they are called positional arguments.  
  • Default Arguments: When we do not provide value for any of the argument at the time of function call, we can still have a default value in the function definition parameters. 
  • Keyword argument: At the time of function call, if we do not want to provide the arguments in the same order as we have given in function definition. We have to provide it using Keyworded Arguments. In this type of argument passing, we provide an argument with its name and value.  
  • Variable-length argument: This is a very important type of parameter, where we can receive a variable length of arguments. If we are not sure about the number of arguments that are going to come to the function parameters through a function call, we receive the arguments in Variable-length arguments.
For Details Explanation --> Click Here

Data Type of python function arguments

As we know all the data types are object in Python, we can pass any data type as an argument in the Python function. At the time of function call, we have to provide the Data as Actual Argument. In the actual argument, we can provide any data type of argument.

For Practical knowledge see the below video:

def & return Keyword and advantages of Python Function

def and return keywords in python

In my Previous Post, I talked about the Introduction of functions, where we discussed how to create the first python function. At the time of the creation of the first python function, we used two important keywords def and return.

In this post, I am going to discuss those two important terms. read the article till the end and you will understand the importance of def and return keywords in Python. 

After reading this article you will have a clear idea about the purpose of the def keyword in python and what does def do in python.

So, let's get started with the def keyword.

def Statement

def is used to define a function. define means give the definition of the function. We start any function by def <Fun_Name> ( ), here function name is a valid identifier name and the two enclosing small brackets denote this is a function. Inside this two small parenthesis, you can provide arguments. Below are the important features of the function's def keyword:
  • def executed at runtime (Remember, all we have in Python is runtime; there is no such thing as a separate compile time).
  • The def statement is used to creates a function object with the name given after the def keyword. It is generally the function name we have provided.
  • The definition of function happens at execution time. That means an object is created at runtime with the function name. Now as shown in the following diagram, we can assign a function name to a variable. That variable can call the function Now:
Python functions

Return Statement

return is used to return the computed result from the function to the caller of the function. the return keyword is generally used at the end of the function, but we can use this keyword at any suitable place in our python function. The syntax of writing the return keyword is return [<var>].  It is not compulsory to give the [<var>], we can omit return keyword also. 

When we give the variable (var), the function returns the variable to the caller. If we do not give the return keyword the None will be returned to the caller.
  • It returns values back to the caller.
  • It is not compulsory to provide return statements in every function, OR we can use only return in place of return <variable>.
  • If only return is used OR nothing is used it returns None.
Python Function
Return statement
A function can return literal, variable or any expression. If we return a literal the value will be returned directly. In the case of a variable, the variable's value will be returned and in the case of expression, the resultant value after calculation will be returned. You can understand the different values with the return keyword by the following image:

Function can return 

return statement in python function
Return Statement

Returning more than one value:-

Using the return statement Programmer can return more than one value also. The programmer has to provide all the values in the comma-separated form. The values will be returned in the same order in which the Programmer writes them in the return statement. So, at the time of receiving the values at the place from where the function was called; the values should be received in the same order.

you can understand it with the following program. Here I am returning three literals 1, 2, 3 from the function fun(). I am receiving it in the same order a, b, c. So, the 1 will go into a, 2 will go in b, and 3 will go into c.

returning more than one value

Types of Functions

There are mainly three types of functions.
  • Built-in Functions
  • Ex. – print(), len()
  • Functions defined in Modules
  • Ex. – math module [ sin() ]
  • User Defined Functions
  • Ex.- we have seen DoSomething() in the previous Slide.

The flow of Execution in a Function Call

The order of execution of the statements at the runtime is called the flow of execution of a program run.

Advantages of Using Functions

There are many advantages to the functions, some of the advantages are given below.
  • Program development made easy and fast
  • Program testing becomes easy
  • Codesharing becomes possible
  • Code re-usability increases
  • Increases program readability
  • Function facilitates procedural abstraction
  • Functions facilitate the factoring of code

For more detail watch the below video:

Introduction to Functions in Python (Class 12 Computer Science)

Introduction to Functions in Python (Class 12 Computer Science)


If you are looking for Python Functions Introduction and want to learn Python Functions from Basics, you have landed on the correct page. 

Here you will get to know the basics of Python Function, I will discuss all the basic details from What is Function? How to Write your Own Function

If you do not have any other computer programming knowledge, then Function terms will be new to you. You can consider function as something that does your work when you call it.

In Computer Programming you can Consider a Function as a block of code, it will do some Operation (Task) for you.

In CBSE Class 12 Computer Science syllabus, you will have to learn Python functions, Functions Parameters, and it's working. So, let's now discuss Functions in Python with technical details.

Introduction to Functions in Python

  • A function can be defined as a single related task, which is written as a block of codes.
  • It only runs when it is called.
  • We can pass data to the function when we call a function, these are known as parameters.
  • A function can return data as a result of using the return statement.
  • We have already used some python built-in functions like print(), len() etc. We can also create our own functions. These functions are called user-defined functions.
If you have not understood the above points don't worry. I will explain each point in a very simple and interesting way.

Let's consider a cook in your house as a Function. You provide necessary items (e.g. Vegetables, Oils, Flour, etc.) for cooking to your cook and he returns you the cooked (ready to eat) food.

In the same way a Function in programming a coding block where you provide necessary items (parameters) to your functions and it returns you the result. Sometime Parameters are also not required, it is as per the working of the functions.

Similarly, we create a function for a single related task. You can make the similarity with the cook as he will only make food (single related task) and may not do another task of yours (e.g. your office work).

Now we have talked enough about the function, we can now go into the coding part. We will write out First Python Function.

Writing and Calling the first Function

Writing and Calling the first Function

Above image shows the simplest Python function Example. In python, we used def keyword to define a function. After function name (DoSomething) we enclose it with small brackets, we can provide parameters inside these brackets. In this case, we have not provided any parameters.
We will use indented (with space) to write code inside a function, this is called function body. In the end, we have used the return keyword to return the result of the function's computation.

Writing and Calling the first Function

  • To call the function we will just write the name of the function with brackets (see the line -> var = dosomething() ).  When the python interpreter sees this line it calls the functions defined with this name.
  • dosomething() will we used to call the function (see the line -> def dosomething()) all the lines of the function will be executed line by line.
  • In the end, the result of our function will be returned (see the line -> return value). 
  • Now this result will be saved to var (see the line -> var = dosometing()).
  • In the above case, the return is returning the value variable whose value is 1. So, var will have 1 and the output will be printed as 1.
For more detail watch the below video:

For Practical knowledge see the below video: