Day 2 in Python

Function :
A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function.

There are two types of function in python.
Built-in library function (pre-defined function)
User-def…


This content originally appeared on DEV Community and was authored by varatharajan

Function :
A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function.

There are two types of function in python.
Built-in library function (pre-defined function)
User-defined function

*Built-in library function: *
There are Standard functions in Python that are available to use.

for Example :
input()
print()

input() function :
The input() function allows user input.
for example :
x = input("Enter your name : ")

print() function
The print() function prints the specified message to the screen, or other standard output device.
for example
print("welcome to our class")

User-defined function:
We can create our own functions based on our requirements.

  We can define a function in Python, using the def keyword. We can add any type of functionalities and properties to it as we require. 

for example

A = int(input("Enter your A value"))
B = int(input("Enter your B value"))
C = input("Enter your operator")

def calculate(A,B,C):
if C == '+':
print("Addition--->",A,B)
if C == '-':
print("Substractionn---->",A-B)

calculate(A,B,C)

*Result *
Enter your A value10
Enter your B value20
Enter your operator+
30
Enter your A value20
Enter your B value10
Enter your operator-
10

30


This content originally appeared on DEV Community and was authored by varatharajan


Print Share Comment Cite Upload Translate Updates
APA

varatharajan | Sciencx (2024-11-12T18:46:52+00:00) Day 2 in Python. Retrieved from https://www.scien.cx/2024/11/12/day-2-in-python/

MLA
" » Day 2 in Python." varatharajan | Sciencx - Tuesday November 12, 2024, https://www.scien.cx/2024/11/12/day-2-in-python/
HARVARD
varatharajan | Sciencx Tuesday November 12, 2024 » Day 2 in Python., viewed ,<https://www.scien.cx/2024/11/12/day-2-in-python/>
VANCOUVER
varatharajan | Sciencx - » Day 2 in Python. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/12/day-2-in-python/
CHICAGO
" » Day 2 in Python." varatharajan | Sciencx - Accessed . https://www.scien.cx/2024/11/12/day-2-in-python/
IEEE
" » Day 2 in Python." varatharajan | Sciencx [Online]. Available: https://www.scien.cx/2024/11/12/day-2-in-python/. [Accessed: ]
rf:citation
» Day 2 in Python | varatharajan | Sciencx | https://www.scien.cx/2024/11/12/day-2-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.