top of page
Search

Functions in Python

Writer's picture: Abhinaw TripathiAbhinaw Tripathi

Functions A functions is a block organized and re-usable code and use to perform certain action.Pyhthon comes with lot of built in functions such as print("hello world") str(3) == "3" int("5") == 15 username = input("Enter the user's name: ") So now let's create our own functions.So for this you can use PyCharm editor I will provide the code here and you can run it directly using pycharm. functions.py : students = [] def get_students_titlecase(): student_titlecase = [] for student in students: students_titlecase = student.title() return students_titlecase def print_students_titlecase(): students_titlecase = [] for student in students: students_titlecase=student.title() print(students_titlecase) def add_student(name) : students.append(name) student_list = get_students_titlecase() add_student("Abhinaw") So actually I have by knowingly added some repeated code in functions which can be removed.Lets see def print_students_titlecase(): students_titlecase = get_students_titlecase() print(students_titlecase) So if you write functions for single responsibility then it will be very helpful to write Unit Testing cases and code will be organized too. 


8 views0 comments

Recent Posts

See All

Lambda Functions in Python

So Lambda Functions are just an anonymous function.they are very simple just saves your space and time.they are useful in case of higher ...

Generator Function - Yield Python

So Yield is a keyword.first let's take an example. student = [] def read_file(): try: f=open("students.txt","r") for student in...

Opening,Reading and Writing Python

Let's save our data in a file and read from that file again when we re-open our app. So let's take an example: Let's take an example: ...

© 2016 by Abhinav Tripathi

  • Facebook Clean Grey
  • Twitter Clean Grey
bottom of page