Python programming for beginners by Tanjimul Islam Tareq

Python programming for beginners by Tanjimul Islam Tareq

Author:Tanjimul Islam Tareq
Language: eng
Format: epub
Publisher: BookRix


class Student(Person):

def init(self, name, age, student_id):

super().init(name, age)

self.student_id = student_id

def say_hello(self):

print(f"Hello, my name is {self.name}, I'm {self.age} years old and my student ID is {self.student_id}")

Output:

student = Student("Mike", 20, 12345)

student.say_hello()

In this example, we are creating a new class called Student that inherits from the Person class. The Student class adds a new attribute called student_id, and overrides the say_hello method to include the student_id in the output. We then create an object of the Student class and call the say_hello method.

2.2.2 Functional Programming

Python also supports functional programming concepts, such as higher-order functions, lambda functions, and map/reduce/filter functions.

- Higher-order functions: A higher-order function is a function that takes another function as an argument or returns a function as its result. For example:

def apply_function(f, x):

return f(x)

def square(x):

return x * x

result = apply_function(square, 2)

print(result)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.