The filter() Method
The filter() method in Python is used to filter elements of the data structure using a conditional function's truthy value.
The conditional function must return a Boolean value i.e. the returned values should be either true or false.
Syntax:
filter (function, iterable)
Parameters:
The function accepts two parameters.
- function: The Boolean function that checks for the values.
- iterable: An iterable on a data structure to pass values to the function.
Return value:
The method returns an iterable after filtering off the values from using the function.
Class and method used:
- Class : Student
- Method : getStudentInfo() : gets input of the student information from the user.
- Method : printStudentInfo() : print in student information to the screen.
- Method : search() : To return whether the student has qualified or not based on the inputted min percentage.
- Variable : rollno : To store roll number of the student.
- Variable : name : To store name of the student.
- Variable : percentage : To store the percentage of the student.
Program to illustrate the working of filter method
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer