DEV Community

yugalakshmi
yugalakshmi

Posted on

Functions in Python-3

  1. Why Do We Need Functions?

Functions provide many benefits:

  1. Code Reusability: We can use the same code multiple times.
  2. Easy Maintenance: Changes can be made easily.
  3. Readability: Code becomes easier to understand.
  4. Modularity: Large programs can be divided into small parts.
  5. Easy Testing: We can test each function separately.

5. Predefined Functions
Python already provides some built-in functions. We can use them directly.

Examples:
print("Good Morning")

print(bin(4))
print(bin(5))

Output:

Good Morning
0b100
0b101

  • print() displays output.
  • bin() converts an integer into a binary string.

Top comments (0)