<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pythonfunctions on Janusworx</title><link>https://janusworx.com/tags/pythonfunctions/</link><description>Recent content in Pythonfunctions on Janusworx</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>feedback@janusworx.com (Mario Jason Braganza)</managingEditor><webMaster>feedback@janusworx.com (Mario Jason Braganza)</webMaster><copyright>© 2026, Mario Jason Braganza</copyright><lastBuildDate>Fri, 24 Jul 2020 11:32:03 +0530</lastBuildDate><atom:link href="https://janusworx.com/tags/pythonfunctions/index.xml" rel="self" type="application/rss+xml"/><item><title>A Hundred Days of Code, Day 015 - Python, Advanced Functions, Done!</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-015-python-advanced-functions-done/</link><pubDate>Fri, 24 Jul 2020 11:32:03 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-015-python-advanced-functions-done/</guid><description>&lt;p&gt;Delving deeper into Python functions and learning more about them, using &lt;a href="https://store.lerner.co.il/advanced-python-functions/" target="_blank" rel="noreferrer"&gt;Reuven Lerner’s Advanced Python Functions Course&lt;/a&gt;&lt;/p&gt;
&lt;!-- TEASER_END --&gt; 

&lt;h2 class="relative group"&gt;Notes
 &lt;div id="notes" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#notes" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;co_*&lt;/code&gt; series of attributes &lt;em&gt;inside&lt;/em&gt; the &lt;code&gt;__code__&lt;/code&gt; attribute inside most functions gives a wealth of information about a function.
&lt;ul&gt;
&lt;li&gt;For example, looking up the argcount attribute for some function hello, with &lt;code&gt;hello.__code__.co_argcount&lt;/code&gt; will give us the number of arguments &lt;code&gt;hello&lt;/code&gt; takes.&lt;/li&gt;
&lt;li&gt;And doing a &lt;code&gt;hello.__code__.co_varnames&lt;/code&gt; will give us a tuple of all the local variables in a function&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hello.__code__.co_code&lt;/code&gt; contains the compiled bytecode for the function.
&lt;ul&gt;
&lt;li&gt;Importing the disassembler &lt;code&gt;import dis&lt;/code&gt; and running it on the bytecode, &lt;code&gt;dis.dis(hello)&lt;/code&gt; will show us what’s in there.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hello.__code__.co_flags&lt;/code&gt; keeps a track of whether the function has * arguments or not via a binary switch. (It holds many parameters, one of which is the on/off switch for *args)
&lt;ul&gt;
&lt;li&gt;if said switch is set, the function checks for such arguments at runtime and turns them into a tuple to process.&lt;/li&gt;
&lt;li&gt;they are set for *args via the &lt;code&gt;hello.__code__co_argcount&lt;/code&gt; switch (0/1) and for keyword arguments with the &lt;code&gt;hello.__code__.co_kwonlyargcount&lt;/code&gt; switch.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;__defaults__&lt;/code&gt; attribute keeps all the functions default variable values. If I don’t supply a value to some parameter, the function will look in here, to see if a default value exists. &lt;code&gt;hello.__defaults__&lt;/code&gt; could hold a last name default, for example, if I want my hello function to work even if no last name was supplied, and it actually expected a full name.
&lt;ul&gt;
&lt;li&gt;do &lt;em&gt;&lt;strong&gt;not&lt;/strong&gt;&lt;/em&gt; use mutable defaults. an empty list or dictionary for example.&lt;/li&gt;
&lt;li&gt;set the default to &lt;code&gt;None&lt;/code&gt; first in such case and then create the list when the function runs at runtime.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The last thing I learnt about were nested functions.
&lt;ul&gt;
&lt;li&gt;I can nest them two/three/as many levels deep as I wish. Practically, most folks do two or three.&lt;/li&gt;
&lt;li&gt;When an inner function takes the variables of its enclosure and does something with it and returns stuff…? those kinds of functions are called closures.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;

&lt;h2 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;The course so far is Reuven making simple functions and then breaking them down and explaining functionality in &lt;em&gt;painstaking detail&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;Reuven is an awesome teacher! I would gush about him every post, but then it would get too much 😂. So once per course is good&lt;/li&gt;
&lt;li&gt;I kept looking at the disassembled code and wondering, what language it was. I still don’t know. My ‘educated’ guess is that it is a level of standard pseudo-assembly code for some phantom standardised processor. Once I had that mental model in mind though, all of it started making a lot more sense. This brought memories of Z80 assembly, I learnt in the mid 90s&lt;/li&gt;
&lt;li&gt;This was fun to do! Onwards to Advanced Objects!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/pythonfunctions/" &gt;Read all about my Python Functions journey here&lt;/a&gt;&lt;/p&gt;</description></item><item><title>A Hundred Days of Code, Day 010 - Python Functions, Basics Done!</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-010-python-functions-basics-done/</link><pubDate>Fri, 17 Jul 2020 19:36:18 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-010-python-functions-basics-done/</guid><description>&lt;p&gt;Today was hard!&lt;/p&gt;
&lt;!-- TEASER_END --&gt; 

&lt;h3 class="relative group"&gt;Notes
 &lt;div id="notes" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#notes" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;‘*args’&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;way to get multiple arguments without having to assign placeholders for them&lt;/li&gt;
&lt;li&gt;it scoops up all the arguments and gives it to the function in a &lt;em&gt;tuple&lt;/em&gt;. I could then loop over it with &lt;em&gt;for&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;I just put * in front of one of my placholders et voilà, &lt;code&gt;def example_func(*catch_everything)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I can define placeholders to catch specific arguments, but those need to be &lt;em&gt;before&lt;/em&gt; my ‘*args’.&lt;/li&gt;
&lt;li&gt;Edge Case: I could have my arguments in a list/tuple already. I can just add the structure with a * in front of it and Python will unpack it for me. If I have a list, &lt;code&gt;catch_me_if_you_can=[1,2,4]&lt;/code&gt; then I can pass the &lt;em&gt;elements&lt;/em&gt; individually, as arguments with a &lt;code&gt;def example_func(*[catch_me_if_you_can])&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Another kinda frequent edge case: ‘*args’ catches everything that is unassigned. so if i have something with a default value, it will get trampled by the data from my args. Best thing to do is to set the default &lt;em&gt;after&lt;/em&gt; the ‘*args’ like so, &lt;code&gt;example_func(a, *args, b=10)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Keyword Arguments&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Normally in the form of &lt;code&gt;name = value&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Kinda like addressing lists vs dictionaries. Where instead of an index, I can now call an argument with a name.&lt;/li&gt;
&lt;li&gt;So I can go &lt;code&gt;def name(FirstName='', LastName='')&lt;/code&gt; and then put in stuff in whatever order I want to like &lt;code&gt;name(LastName='Brontë', FirstName='Emily'&lt;/code&gt;. Pretty handy!&lt;/li&gt;
&lt;li&gt;Try not to mix and match positional and keyword arguments. Python looks for positional arguments first, &lt;em&gt;then&lt;/em&gt; keyword arguments. So if you have them, then the positional arguments &lt;em&gt;have to come first!&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;‘**kwargs’&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;these scoop up keywords arguments into a &lt;em&gt;dictionary&lt;/em&gt;. I can do everything with this, just like any other dictionary&lt;/li&gt;
&lt;li&gt;I just put * in front of one of my placholders et voilà encore, &lt;code&gt;def example_func(**catch_everything)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Combining Arguments&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Arguments in decreasing order. Stick to the order as far as possible.
&lt;ul&gt;
&lt;li&gt;mandatory parameters (no defaults)&lt;/li&gt;
&lt;li&gt;optional parameters (with defaults)&lt;/li&gt;
&lt;li&gt;*args&lt;/li&gt;
&lt;li&gt;**kwargs (with and without defaults)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use them for different kinds of input&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Variable scopes&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Just because I have indentation, with an if or an else or a for, does &lt;em&gt;not&lt;/em&gt; mean that I change a variable’s scope. Variables within those indented blocks could still be global, or the scope of the thing above&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;slight&lt;/em&gt; exception is the variable within comprehensions. Variables inside them, have their own private scope&lt;/li&gt;
&lt;li&gt;The scope changes, mainly, when we define functions. Generally …
&lt;ul&gt;
&lt;li&gt;If I am &lt;em&gt;in&lt;/em&gt; a function, I’m in a local scope&lt;/li&gt;
&lt;li&gt;If I am out of it, I’m in a global scope&lt;/li&gt;
&lt;li&gt;with some exceptions&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;So always think, am I in a function body … or not? (excepting comprehensions)&lt;/li&gt;
&lt;li&gt;When Python looks for variable values it looks in the LEGB sequence. (left to right).
&lt;ul&gt;
&lt;li&gt;Local (starts here if I’m in a function)&lt;/li&gt;
&lt;li&gt;Enclosing&lt;/li&gt;
&lt;li&gt;Global (starts here if I’m &lt;em&gt;not&lt;/em&gt; in a function, rather in the main body of the program)&lt;/li&gt;
&lt;li&gt;Built-in&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;globals&lt;/code&gt; function will have all the global variables for the program. It’s a dict with variable names as keys and the variable assignments as values&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;locals&lt;/code&gt; function will have all the local variables for a function in the program, when it runs. It’s also a dict with variable names as keys and the variable assignments as values or I could also look at the &lt;code&gt;function_name.code.co_varnames&lt;/code&gt; to peek at the local stuff
&lt;ul&gt;
&lt;li&gt;Parameters to a function are also local variables.&lt;/li&gt;
&lt;li&gt;I should define my local variables, before I use them in a function, or I get an &lt;code&gt;UnboundLocalError&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If I want to use and modify a global variable in a function, I should declare it at the beginning of my function. For example, if I have a global variable x, and I want to use it in a function, then I say &lt;code&gt;global x&lt;/code&gt; in the beginning of the function.&lt;/li&gt;
&lt;li&gt;I &lt;em&gt;can&lt;/em&gt; mutate elements of global variable, if they are mutable structures. As in, I cannot change list A to another set of entries, but I can append to list A, or delete items from list A. As long as you are not &lt;em&gt;assigning&lt;/em&gt; to a variable, rather using object methods, you should be ok.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The built-ins scope, houses many things that are needed by Python, but are not reserved keywords. Stuff like &lt;code&gt;list&lt;/code&gt;. I can use it to create lists, but it’s not reserved. I can redefine it if I want to (or more commonly redefine it by mistake)
&lt;ul&gt;
&lt;li&gt;This feels like one of the few places, Python allows me to shoot myself in the foot.&lt;/li&gt;
&lt;li&gt;Do a &lt;code&gt;dir(__builtins__)&lt;/code&gt; and review the names every now and then, and &lt;em&gt;don’t&lt;/em&gt; use them in your code.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Kinda Advanced Stuff&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;While I said, they were verbs, functions can alse be nouns. I can just pass them as objects to other functions or elsewhere.&lt;/li&gt;
&lt;li&gt;I can pass a function as an argument as in the case of &lt;code&gt;sorted(someIterableofPositiveNegativeNumbers, key=abs)&lt;/code&gt; where I am passing the &lt;code&gt;abs&lt;/code&gt; function as a keyword to the &lt;code&gt;sorted&lt;/code&gt; function, which then uses &lt;code&gt;abs&lt;/code&gt; to get the absolute values of the numbers first and then sorts them according to those values.&lt;/li&gt;
&lt;li&gt;I can collect arguments for the inner functions I call with &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt; and then pass to them again with &lt;code&gt;*args&lt;/code&gt; and &lt;code&gt;**kwargs&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;I can also take some data as an argument along with a function and apply that function to that data. Like I did above. The main function I create acts like some glue program. This process of applying function to data, is called mapping and the functions I create to do this are map functions. Python has a built in &lt;code&gt;map&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;I can create functions, plop them into a dictionary and then call them as needed in my actual function, by accessing the dictionary keys and supplying arguements. This approach is called a dispatch table&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Getting used to the way, Python behaves. And beginning to love its consistency for the most part.&lt;/li&gt;
&lt;li&gt;I write slow, step by step code. while it works, Reuven’s solutions are short and make me go, oh why did I not think of that? Maybe optimised thinking will come with time?&lt;/li&gt;
&lt;li&gt;I have to use Python tutor a &lt;em&gt;lot&lt;/em&gt; to get what is actually happening.&lt;/li&gt;
&lt;li&gt;I’ve learnt to just dive in blind when begining to write programs. The more I think about stuff, the more I feel, like I can’t do this. So I just start. And build it line by line, error by error. And more often than not, it solves it self. Optimised solutions present themselves &lt;em&gt;after&lt;/em&gt; I have the rough and ready solution done. “Aah! I could’ve written it &lt;em&gt;this&lt;/em&gt; way”&lt;/li&gt;
&lt;li&gt;And I am done with the introduction to functions! Hurrah! This course stretched me a bit, and showed me I still have a ways to go.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/pythonfunctions/" &gt;Read all about my Python functions journey here&lt;/a&gt;&lt;/p&gt;</description></item><item><title>A Hundred Days of Code, Day 009 - Python Functions, Basics</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-009-python-functions-basics/</link><pubDate>Thu, 16 Jul 2020 16:12:47 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-009-python-functions-basics/</guid><description>&lt;p&gt;Started up with learning about Python function basics, today. Notes follow. Using the &lt;a href="https://store.lerner.co.il/python-functions/" target="_blank" rel="noreferrer"&gt;Lerner pool of wisdom, as usual&lt;/a&gt;.&lt;/p&gt;
&lt;!-- TEASER_END --&gt;
&lt;p&gt;&lt;strong&gt;Why do we need functions?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DRY &lt;em&gt;(Don’t Repeat Yourself)&lt;/em&gt;, because we can take stuff that is repeatable, assign it a nickname and just call that nickname over and over, instead of tediously writing all that stuff over and over and over&lt;/li&gt;
&lt;li&gt;If want to modify something, I can just call it (by the nickname) and then add my little spice to it. Like I have the recipe to an omlette written down somewhere, I can then just add a little note with secret ingredients at the bottom of that recipe to create a better or a different omlette.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Functions are objects.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We can think of them as verbs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Parentheses in Python (at the end of functions) basically mean, I want to execute, this here thing, on the left&lt;/p&gt;
&lt;p&gt;I can run help on a function to get some information about it.&lt;br&gt;
&lt;code&gt;help(str.upper)&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We don’t tack parentheses on the function, when I am lookif for its help, because I don’t want to run the darned thing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Creating/Defining a function&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We define a function using the &lt;code&gt;def&lt;/code&gt; keyword. It’s followed by the name you want to call it by, followed by parantheses terminated by a colon
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;def hello():&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This is actually a two step thing, even though I’ve always thought of it as one.
&lt;ul&gt;
&lt;li&gt;first, I create a function object.&lt;/li&gt;
&lt;li&gt;then, I assign it a name.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Functions in Python (unlike other languages), have the same name space as the rest of our Python program. I cannot have a function called x and also a variable called x&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Returning results&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Similar to math functions, even Python functions return values after running them&lt;/li&gt;
&lt;li&gt;The default is &lt;code&gt;None&lt;/code&gt;, unless you actually, explicity tell the function to return something&lt;/li&gt;
&lt;li&gt;If you want to catch the results of what you are doing with the function, remember to return it.&lt;/li&gt;
&lt;li&gt;A function can return whatever you want. statements, values, other functions etc.&lt;/li&gt;
&lt;li&gt;Which is good and all, but remember to do this with intent. I ought to think about what I want to return and document it well&lt;/li&gt;
&lt;li&gt;If I am returning multiple values of varying types, it comes back as a tuple. Not as different objects. I need to unpack them and assign them to multiple values explicity&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Documenting Functions&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The help function needs something to read and tell the user about what our functions do. Ergo …&lt;/li&gt;
&lt;li&gt;Use docstrings (Documentation Strings) to do it.
&lt;ul&gt;
&lt;li&gt;What are docstrings? If the first line in a function is a string, then that string is seen by the help system as a docstring and used for documentation.&lt;/li&gt;
&lt;li&gt;Use triple quotes around the string. I can have multiple lines in there&lt;/li&gt;
&lt;li&gt;The convention is to document what a function receives (the input), what it returns (the output) and what it modifies.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;		&lt;span class="s2"&gt;&amp;#34;&amp;#34;&amp;#34;This is it! The docstring! This will help me figure out what the hello function does!
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;		or more seriously
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;		expects: No arguments
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;		modifies: Nothing
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;		returns: A friendly greeting
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;&lt;span class="s2"&gt;		&amp;#34;&amp;#34;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;		&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello, hello :)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;br&gt; 
**Arguments** 
&lt;p&gt;Functions need stuff to work with.&lt;br&gt;
We supply them using arguments.&lt;br&gt;
Just a fancy name for the data we pass along to the function.&lt;br&gt;
E.g. If a function returns a fancy format of our name, there must be some mechanism to pass our name across to the function. Arguments are how we do it. We don’t actually argue with the programe :P&lt;/p&gt;
&lt;p&gt;A function can take any number of arguments. We just put them between the parentheses, seperated by commas&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Positional Arguments&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;def hello(first, second):
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; print(f&amp;#39;Hello, {first} and {last}&amp;#39;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;In the code above, I can call the function with &lt;code&gt;hello('Tyche','Hestia')&lt;/code&gt; and it will assign Tyche to first and Hestia to second, because I typed them in that order.&lt;/li&gt;
&lt;li&gt;These are called positional arguments&lt;/li&gt;
&lt;li&gt;When I define a number of arguments, I need to pass &lt;em&gt;all&lt;/em&gt; the arguments along. I can’t make space for two and pass only one or none.&lt;/li&gt;
&lt;li&gt;I can supply defaults, so that if the user does not supply all the arguments, the default is used in its place&lt;/li&gt;
&lt;li&gt;If some arguments cannot have defaults and are a must, they must come &lt;em&gt;before&lt;/em&gt; the ones that are optional and can have defaults.&lt;/li&gt;
&lt;li&gt;How does Python know, how many to expect?
&lt;ul&gt;
&lt;li&gt;When Python defines the function, it records the definition and makes a note of what it needs to run the function properly
&lt;ul&gt;
&lt;li&gt;If I look at the guts of the &lt;code&gt;hello&lt;/code&gt; function with a &lt;code&gt;hello.__code__.co_argcount&lt;/code&gt; it’ll tell me, it has recorded two.&lt;/li&gt;
&lt;li&gt;If I supply defaults, they are recorded in a &lt;em&gt;seperate&lt;/em&gt; place called &lt;code&gt;hello.__defaults__&lt;/code&gt; and it supplies the requisite information, so the &lt;code&gt;argcount&lt;/code&gt; always stays at the required number of arguments&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A little dazed today, so calling it quits early.&lt;/p&gt;

&lt;h3 class="relative group"&gt;Learning / Feedback/ Experiences from doing exercises
 &lt;div id="learning--feedback-experiences-from-doing-exercises" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#learning--feedback-experiences-from-doing-exercises" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;I keep looking for elegant, one statement like solution to problems and get frustrated. Reuven then shows up with a brutally efficient solution that has four if statements. I should remember to be more workmanlike, before I turn craftsman&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/pythonfunctions/" &gt;Read all about my Python functions journey here&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>