Python Classroom Series – 10/Mar/2020

Little bit more about functions

  • Till now we had look at fixed set of arguments
def add(number1, number2, number3):
    pass

## add(3,5,7)
  • One solution looks like
def add(numbers):
    result = 0
    for number in numbers:
        result += number

# add([3,5,7])
  • If we need a function, which behaves as shown below we have *args to the the rescue in python
add(1,2)

add(1,2,3)

add(1,2,3,4,5,6)
  • A sample implementation of add numbers using *args
def add(*args):
    print(f"Type of args is {type(args)} and value is {args} ")
    result = 0
    for arg in args:
        result += arg
    return result

print(add(1))
print(add(1,2))
print(add(1,2,3,4,5,6,7,8,9))
  • Now if want a function with variable arguments with names
add(number1=1, number2=2, number3=3)

Developer Work-Organization Workflow

Preview

Preview

Preview

Preview

Version Control Systems

  • This is a software system where developers commit (send/store) the source code of the project.
  • Version Control Systems help in navigating through history of changes done in the code
  • It also helps in multiple team members working on same project.

How to test the code

  • Manually: debug the code by passing multiple inputs and check all the conditions around
  • Test Harness Tools/Unit Testing Tools: Every Language supports unit testing frameworks to test the written code.
    • pytest

Programming Exercise

  • Create a account in GitHub
  • Hacker Rank

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin