What is PYTHON?

Python is a lazy Programming language. In other languages like C, CPP, Java, there consists of large number of code. But in Python, we can write same code in few lines. For example, in other languages we used to use curly bracket, semi-colon,etc. In python there are no semi-colon, no curly brackets.

While using loops, we will use colon(:) after condition and then on next line indentation that is four space or one tab. There should be proper indentation otherwise it will throw an error. In this if we want short output then we have to write short code.

For example:

print(“Hello world”)

Output: Hello world

Example for adding two numbers:

num1=1.5

num2=3

sum=num1+num2

print(“Addition of two numbers is {0}.format(num1, num2, sum))

Output: Addition of two numbers is 4.5

As seen above, we have directly written variables without giving data type and and creating main function. This is speciality of python.

Function: Function is a block of code which only runs when it is called. If we have to write function then we will use def keyword.

Body of function: Body of function where we use to write statement or block of code which we have to execute.

Calling function: To call a function, use the function name followed by parenthesis

For Example:

def my_function(): // function definition

print(“Good Morning Everyone”) //body of function

my_function() //function call

Output: Good Morning Everyone

Parameters and Arguments: Parameters and Arguments can be used for same things: information that are passes into a function. A parameter is the variable listed inside the parenthesis in the function definition. An argument is the value that is sent to the function when it is called.

For Example:

def my_function(fname, lname): // parameters inside function

print(fname + ” ” = lname)

my_function(“Sonali”, “pal”) //arguments

Output: Sonali pal

Edusera
Logo
Open chat
1
Scan the code
Hello!👋
Can we help you?