pass Statement
If we have a function definition with no content, put in the pass statement to avoid getting an error.
def ourfunction():
pass
“The Archer’s Wisdom”
In the quaint town of Willowbrook, nestled amidst rolling hills and lush forests, there lived a young man named Ethan. Ethan was known far and wide for his incredible talent in archery. From a young age, he had honed his skills with the bow and arrow, spending countless hours perfecting his aim and technique.
Despite his prowess, Ethan had a tendency to push himself too hard. He was always striving to outdo his previous accomplishments, constantly pushing the boundaries of his abilities. His friends and family often warned him to slow down, to take a moment to appreciate his achievements and enjoy the simple pleasures of life. But Ethan was driven by a relentless desire to win, to be the best at whatever he set his mind to.
One day, as Ethan was practicing in the town square, a stranger approached him. The man was old and weathered, with a twinkle in his eye that hinted at a lifetime of wisdom.
“Young man,” the stranger said, “I’ve been watching you shoot, and I must say, you have quite a talent. But remember, winning is not just about skill—it’s also about having the wisdom to know when to stop.”
Ethan shrugged off the man’s words, eager to get back to his practice. But as the days passed, his mind kept returning to the stranger’s advice. Slowly, he began to realize that perhaps there was more to winning than simply being the best.
With a newfound sense of purpose, Ethan decided to approach his training with a different mindset. Instead of pushing himself to the limit, he focused on developing a winning habit—a routine that balanced hard work with rest and relaxation. He learned to listen to his body, to recognize when it was time to push forward and when it was time to slow down and recharge.
As Ethan’s approach to archery began to change, so too did his outlook on life. He discovered the power of common sense, of listening to the wisdom of those around him and trusting in his own intuition. And in doing so, he found a newfound sense of balance and fulfillment.
Years passed, and Ethan’s reputation as a skilled archer only continued to grow. But more importantly, he had found peace within himself—a peace that came from knowing that true victory lay not in outdoing others, but in mastering the art of living a life well-lived, guided by wisdom, common sense, and the courage to set healthy boundaries.
Python Recursion
In python a function can call itself.
Use: Looping
To be avoided while using recursion:
- Writing a never ending program.
- Writing a program which uses excessive power.
- Writing a program which uses excess memory.
Example
def recursion(m):
if(m > 0):
result = m + tri_recursion(m – 1)
print(result)
else:
result = 0
return result
print(“\n\nRecursion Example Results”)
recursion(6)
Return Values
A return value returns function value.
def Ten_function(x):
return 10 * x
print(Ten_function(3))
print(Ten_function(5))
print(Ten_function(9))
Passing a List as an Argument
We can send any data type as argument to a function (string, number, list, dictionary etc.), and it will be treated as the same data type inside the function.
E.g. if we send a List as an argument, it will still be a List when it reaches the function:
def cricket_team(teams):
for x in teams:
print(x)
players = [“rohit”, “kohli”, “bumrah”]
cricket_team(players)
Default Parameter Value
If we call a function without argument, it calls default value.
def our_function(state = “Karnataka”):
print(“I am from “ + state)
our_function(“Maharashtra”)
our_function(“Kerala”)
our_function()
our_function(“Telangana”)
Arbitrary Number of Keyword Arguments, **kwargs
Add two asterisks ** before arguments if number of keyword arguments is not known.
def my_optionals(**subject):
print(“His language optional is “ + subject[“lang”])
my_optionals(math = “algebra”, lang = “French”)
Keyword Arguments
Key, value pair arguments can be given to functions in python.
The order can be arbitrary.
def my_subjects(subject3, subject2, subject1):
print(“The first subject is “ + subject1)
my_subjects(subject1 = “English”, subject2 = “Kannada”, subject3 = “Hindi”)
Arbitrary Arguments (*args)
When in doubt about number of arguments, add * before the argument.
def world_cup(*teams):
print(“The World Cup teams are “ + teams[2])
world_cup(“India”, “South Africa”, “Australia”)