<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pythonbasics on Janusworx</title><link>https://janusworx.com/tags/pythonbasics/</link><description>Recent content in Pythonbasics 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>Wed, 15 Jul 2020 19:32:58 +0530</lastBuildDate><atom:link href="https://janusworx.com/tags/pythonbasics/index.xml" rel="self" type="application/rss+xml"/><item><title>A Hundred Days of Code, Day 008 - Python Basics, Lists, Tuples, Dictionaries, Sets and Done!</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-008-python-basics-lists-tuples-dictionaries-sets-and-done/</link><pubDate>Wed, 15 Jul 2020 19:32:58 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-008-python-basics-lists-tuples-dictionaries-sets-and-done/</guid><description>&lt;p&gt;This was an amazing run! Learnt lots.&lt;br&gt;
Done with the basics course.&lt;br&gt;
Woohoo!&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;ul&gt;
&lt;li&gt;
&lt;p&gt;With lists&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Not pythonic to mix types&lt;/li&gt;
&lt;li&gt;can iterate, slice and dice, search, get lengths, transmute them (for e.g. reverse items in them) just like strings&lt;/li&gt;
&lt;li&gt;can have lists of lists!&lt;/li&gt;
&lt;li&gt;lists are mutable, unlike strings. can change items/elements of a list
&lt;ul&gt;
&lt;li&gt;If i create a list from another list, the new list items reference the old list items&lt;/li&gt;
&lt;li&gt;if i want to &lt;em&gt;copy&lt;/em&gt; elements from a list rather than reference them, I’ll go &lt;code&gt;newlist = oldlist[:]&lt;/code&gt; which will copy the elements from the old list into the new one, rather than create references to the old ones&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Realise that there is a difference between changing the values of a variable and between changing elements of a list.
&lt;ul&gt;
&lt;li&gt;When I do &lt;code&gt;x = 2&lt;/code&gt; and &lt;code&gt;y = x&lt;/code&gt; and then change x to be &lt;code&gt;x = 3&lt;/code&gt;, remember that the value of y does not become 3. y continues to point to the original location in memory which holds 2. What I did was to break x’s connection to that value and assign to another value in another location&lt;/li&gt;
&lt;li&gt;On the other hand, when I do &lt;code&gt;x = ['jane', 'jill', 'mary']&lt;/code&gt; and then create a copy with &lt;code&gt;y = x&lt;/code&gt; and then change &lt;code&gt;x[0]='edith'&lt;/code&gt;, what I do in this case is change the &lt;em&gt;actual element.&lt;/em&gt; The references to that object in momory stay unchanged. Which is why &lt;code&gt;y[0]&lt;/code&gt;, which holds references to the same object, will also reflect the change to edith.&lt;/li&gt;
&lt;li&gt;Finally if I go, &lt;code&gt;x = ['athena', 'diana', 'aphrodite']&lt;/code&gt;, now we’re back to the assignment. x will point to this new list while y points to the old one.&lt;/li&gt;
&lt;li&gt;This distinction between changes in assignment vs changes to content is very important, when dealing with mutable/changeable data types like lists&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Append something to a list with .append - &lt;code&gt;list.append(something, something else)&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Heuristic, when a method on a mutable data type, changes data, in returns &lt;code&gt;None&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;So I should just go &lt;code&gt;mylist.append('blah')&lt;/code&gt; and stuff will be done&lt;/li&gt;
&lt;li&gt;If go &lt;code&gt;mylist = mylist.append('blah')&lt;/code&gt; (which I am &lt;em&gt;very&lt;/em&gt; apt to do) the method will change the list, then return &lt;code&gt;None&lt;/code&gt; and &lt;em&gt;that &lt;code&gt;None&lt;/code&gt; will get assigned to mylist&lt;/em&gt;, In effect, erasing the list and causing unnecessary heartache. So, be careful, very careful. Not careless, like Bond, James Bond.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;+=&lt;/code&gt; or &lt;code&gt;.extend&lt;/code&gt; takes an iterable on the right. picks each element. and then assigns them singly to the list on the left.
&lt;ul&gt;
&lt;li&gt;Append can take only one item.
&lt;ul&gt;
&lt;li&gt;If I want to add &lt;code&gt;xyz&lt;/code&gt; as separate entries to mylist that has &lt;code&gt;['a','b','c']&lt;/code&gt;, append will just take it as a big lump and make &lt;code&gt;['a','b','c','xyz']&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Instead I do a +=
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mylist += 'xyz'&lt;/code&gt; or &lt;code&gt;mylist.extend('xyz')&lt;/code&gt;will give me &lt;code&gt;['a','b','c','x','y','z']&lt;/code&gt;, which is what I wanted in the first place&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;it will only work if there are iterables on the right. (strings, lists, dictionaries etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;insert&lt;/code&gt; method will let you insert something at a location in the list.
&lt;ul&gt;
&lt;li&gt;Give it what you want, tell it where you want, and boom!&lt;/li&gt;
&lt;li&gt;&lt;code&gt;mylist.insert('d', 3)&lt;/code&gt; will put d after abc, giving me &lt;code&gt;['a','b','c','d','x','y','z']&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I can replace things in a list by giving it a location and telling it what to put in there.
&lt;ul&gt;
&lt;li&gt;I could do &lt;code&gt;mylist[0]='artemis'&lt;/code&gt; and the list will change to &lt;code&gt;['artemis','b','c','d','x','y','z']&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I could also give it a slice along with a list of what to put in there. Doing &lt;code&gt;mylist[1:2]=['josephine','lisbeth']&lt;/code&gt; will now give me &lt;code&gt;['artemis','josephine','lisbeth','d','x','y','z']&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;if you add additional elements, than what you replace, Python will insert them, growing the list.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Removing things from a list?
&lt;ul&gt;
&lt;li&gt;the .pop method will pop off the last item in a list.
&lt;ul&gt;
&lt;li&gt;If i give it a location, it will remove the item at that index location. &lt;code&gt;mylist.pop(3)&lt;/code&gt; will remove d from mylist giving me &lt;code&gt;['artemis','josephine','lisbeth','x','y','z']&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When I know what I want to remove, I just use the remove method instead of pop.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mylist.remove('josephine')&lt;/code&gt; will remove poor Josephine leaving us with &lt;code&gt;['artemis','lisbeth','x','y','z']&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If I’m not sure, I could check for the presence of an item before I remove it. Should prevent a program from barfing on me if that element isn’t there
&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;if &amp;#39;q&amp;#39; in mylist:
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt; mylist.remove(&amp;#39;q&amp;#39;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;also the remove method only removes the &lt;em&gt;first&lt;/em&gt; instance of something.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Iterating and counting over lists?
&lt;ul&gt;
&lt;li&gt;the for loop!
&lt;ul&gt;
&lt;li&gt;I can use the &lt;code&gt;enumerate&lt;/code&gt; function if I want numbered items out&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;I can iterate over a slice.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;range&lt;/code&gt; function is very list like in its behaviour.&lt;/li&gt;
&lt;li&gt;I can &lt;code&gt;sort&lt;/code&gt; lists.
&lt;ul&gt;
&lt;li&gt;same caveat as above. &lt;code&gt;sort&lt;/code&gt; will change the list in place and return &lt;code&gt;None&lt;/code&gt;. Don’t go assigning &lt;code&gt;mylist = mylist.sort()&lt;/code&gt;. &lt;em&gt;&lt;strong&gt;It won’t work&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;.sort(reverse=True)&lt;/code&gt; will sort in reverse&lt;/li&gt;
&lt;li&gt;sorting between mixed types in a list doesn’t work in Python 3 anymore. The types in a list, ought to be the same.&lt;/li&gt;
&lt;li&gt;Sorting list of lists works by comparing indices&lt;/li&gt;
&lt;li&gt;If I don’t want to change my original list, I can use the &lt;code&gt;sorted&lt;/code&gt; &lt;em&gt;function&lt;/em&gt; on the list.
&lt;ul&gt;
&lt;li&gt;It works on most iterables, not just lists, while the &lt;code&gt;list&lt;/code&gt; method is restricted to lists&lt;/li&gt;
&lt;li&gt;It returns a new sorted list, and keeps the original list intact.&lt;/li&gt;
&lt;li&gt;I can do &lt;code&gt;sorted('something', reverse=True)&lt;/code&gt; will return a reversed list.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I can &lt;code&gt;str&lt;/code&gt; a list and &lt;code&gt;list&lt;/code&gt; a string&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I can &lt;code&gt;split&lt;/code&gt; a string into a list, either by single characters or by a delimiter (a ; or a , or space)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;split without an argument will cut out all white space&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I can &lt;code&gt;join&lt;/code&gt;, strings and lists and stuff, but&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;join works only on a string. it’s a string method&lt;/li&gt;
&lt;li&gt;and that string generally is the glue, that will string what we give it, together&lt;/li&gt;
&lt;li&gt;&lt;code&gt;' '.join(['Hail','Caesar'])&lt;/code&gt; will join the list using that blank space I gave it.&lt;/li&gt;
&lt;li&gt;it works backwards, so that I can feed it any sequence in the end. a list, a tuple, a dictionary … all fair game&lt;/li&gt;
&lt;li&gt;Remember, it won’t work on numbers. It’ll fail.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Tuples, are a kind of weird hybrid of strings and lists.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Like a string, they are immutable&lt;br&gt;
Like a list, they can contain anything at all.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;crazyTuple = (1, 2, 4, 5)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;you create them by enclosing with &lt;code&gt;()&lt;/code&gt; brackets. but that is just for you to know you are creating a tuple. I can just do &lt;code&gt;crazyTuple = 1 2 3 4 5&lt;/code&gt; and that creates a tuple just as well.&lt;/li&gt;
&lt;li&gt;I can do most everything with them just like strings and lists, slice, search, iterate blah blah
&lt;ul&gt;
&lt;li&gt;Typically used to create structures. like &lt;code&gt;bookdetails = ('title', 'author', 'pubdate', 'price')&lt;/code&gt;. you know what to expect, once you see definition. Once we figure that &lt;code&gt;[0]&lt;/code&gt; is the title, it normall will be the same for the other books too.&lt;/li&gt;
&lt;li&gt;Behind the scenes in Python, function arguments are passed as tuples.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Note:&lt;/strong&gt;* If elements in my tuple are mutable (like a list), I &lt;em&gt;can&lt;/em&gt; change &lt;em&gt;their elements&lt;/em&gt;, like appending or deleting items in the list. The tuple however is immutable. I cannot delete/modify the list item as a whole.&lt;/li&gt;
&lt;li&gt;use &lt;code&gt;extend&lt;/code&gt; if you want to append to a list in a tuple&lt;/li&gt;
&lt;li&gt;Since a tuple is immutable, it doesn’t have a sort method. I can however sort by using the &lt;code&gt;sorted&lt;/code&gt; function which will return a sorted list of the elements of the tuple, whill leaving the original tuple untouched.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Unpacking stuff&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If my variables on the left, match up to the number of items in the structure on the right, &lt;code&gt;x, y, z = (10, 20, 30)&lt;/code&gt; then they get assigned to each. &lt;code&gt;x&lt;/code&gt; is assigned &lt;code&gt;10&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;,&lt;code&gt;20&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt;,&lt;code&gt;30&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Dictionaries&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hash tables, hash maps in other languages&lt;/li&gt;
&lt;li&gt;While in a list, I have values of my choice, the index is always numeric. so item 0 is a cookie, item 1 is cookie-dough and so on, with a dictionary, I get to define the indexes too! I can now say endresult is a cookie, ingredient is cookie-dough and on and on&lt;/li&gt;
&lt;li&gt;while if you want to append to a list, you use an append method, if you want to add keys (user defined indexes), you just assign it to a dictionary with its corresponding value. So I can just add &lt;code&gt;cookie_recipe[sugar]=100&lt;/code&gt; to my cookie recipe dictionary above. if the key is already in there, it just gets updated with the new value. if not, the key and the value get added to the dictionary.&lt;/li&gt;
&lt;li&gt;Keys are unique. Values can repeat. But keys can exist only once in a dictionary&lt;/li&gt;
&lt;li&gt;I can use most immutable data types as keys. strings, integers, tuples that don’t contain mutable data like lists etc.&lt;/li&gt;
&lt;li&gt;I can use &lt;code&gt;in&lt;/code&gt; to look for keys in a dictionary. &lt;code&gt;'sugar' in cookie_recipe&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;get&lt;/code&gt; method will look for a key for you. If it exists it will return the key, or if there isn’t, it returns &lt;code&gt;None&lt;/code&gt;. I could even customise the none with a message. If i do &lt;code&gt;d.get('somekey', 'No such key')&lt;/code&gt;, it will print “No such key” if the key isn’t found.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;setdefault&lt;/code&gt; method will set a key in the dictionary along with the value, if it does not already exist in the dictionary. If it exists already, it will return the existing value.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If I want to convert strings to numbers and want to do a sanity check (I would not want to convert text after all, Hello is not a number :P) then I can use the &lt;code&gt;isdigit&lt;/code&gt; method on the string. It’s a &lt;em&gt;string&lt;/em&gt; method to use on &lt;em&gt;strings&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sets, can be thought of as dictionaries without any values.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each value in a set can occur only once.&lt;/li&gt;
&lt;li&gt;create them by going &lt;code&gt;myset = set()&lt;/code&gt; and then I can willy-nilly add values with &lt;code&gt;myset.add(10)&lt;/code&gt; or &lt;code&gt;myset.add(32)&lt;/code&gt;. If I try adding same value twice, no dice. It is stored only once. Every value is unique&lt;/li&gt;
&lt;li&gt;I can use an iterable to add multiple items at once with the &lt;code&gt;update&lt;/code&gt; method. I can pass a list for example, and it will add all the unique values to the list. &lt;code&gt;myset.update([44, 777, 44, 56, 89, 777])&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I cannot have mutable / changeable data as elements of set. No lists, no dicts etc. Strings, Numbers are ok&lt;/li&gt;
&lt;li&gt;While sets &lt;em&gt;look&lt;/em&gt; like lists, they are unordered with no indexing.&lt;/li&gt;
&lt;li&gt;I can iterate over them, though.&lt;/li&gt;
&lt;li&gt;To look for something in a set, use the &lt;code&gt;in&lt;/code&gt; operator&lt;/li&gt;
&lt;li&gt;To remove the item use the &lt;code&gt;remove&lt;/code&gt; method&lt;/li&gt;
&lt;li&gt;I can do set operations. &lt;code&gt;s1 - s2&lt;/code&gt; will show me items that are unique to s1. (it removes the common elements between the sets) or vice versa&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;symmetric_difference&lt;/code&gt; method will show me unique elements from &lt;em&gt;both&lt;/em&gt; sets. stripping off the common elements. &lt;code&gt;s1.symmetric_difference(s2)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;to find if a set is a subset of another I could use the &amp;lt;&amp;gt;= operators. Is s2 a subset of s1? &lt;code&gt;s2 &amp;lt; s1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;I can combine sets (union) &lt;code&gt;s1|s2&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Or I can find the common elements with intersection &lt;code&gt;s1 &amp;amp; s2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&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;Reuven keeps going, Alright? And I keep nodding my head here :)&lt;/li&gt;
&lt;li&gt;Still miss lots of stuff, writing code. Missing colons, no surrounding quotes, missing commas, so many commas … not converting strings to integers and then wondering how I get such large results from simple addition&lt;/li&gt;
&lt;li&gt;But I’m done!&lt;/li&gt;
&lt;li&gt;These were the basics, and I could run through them, but I did not realise I had so many gaps in my basics.&lt;/li&gt;
&lt;li&gt;As I keep saying Reuven is amazing. He points out the pitfalls and keeps reminding me of important issues and shows various methods to solve things, keeps encouraging me and I could go on and on. Lerner fan for life!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/pythonbasics/" &gt;Read all about my Python basics journey here&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>A Hundred Days of Code, Day 007 - Python Basics, Variables, Basic Data Types, Strings and Loops</title><link>https://janusworx.com/work/a-hundred-days-of-code-day-007-python-basics-variables-basic-data-types-strings-and-loops/</link><pubDate>Tue, 14 Jul 2020 18:26:08 +0530</pubDate><author>feedback@janusworx.com (Mario Jason Braganza)</author><guid>https://janusworx.com/work/a-hundred-days-of-code-day-007-python-basics-variables-basic-data-types-strings-and-loops/</guid><description>&lt;p&gt;Started with the &lt;a href="https://store.lerner.co.il/intro-python-fundamentals" target="_blank" rel="noreferrer"&gt;Reuven Lerner, Intro Python:Fundamentals&lt;/a&gt; course today.&lt;br&gt;
Made surprising headway, even though today was crazily demanding with work and personal stuff.&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;ul&gt;
&lt;li&gt;The difference between &lt;code&gt;==&lt;/code&gt; and &lt;code&gt;is&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;If you want to see if two things are equal, use &lt;code&gt;==&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;like, is &lt;code&gt;2+2&lt;/code&gt; == &lt;code&gt;4&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If you want to know if two objects are the same thing. if they are just pointers to the same memory location, use &lt;code&gt;is&lt;/code&gt;. The heuristic is, if you are checking for singleton values, something that there is only one thing of; then in Python, we use &lt;code&gt;is&lt;/code&gt;. Use sparingly . Make sure you check mostly to see if things are the same object or practically to see if something is &lt;code&gt;None&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;mostly to check for the presence or absence of things.&lt;/li&gt;
&lt;li&gt;like &lt;code&gt;x = None&lt;/code&gt; and then I go check &lt;code&gt;if x is None&lt;/code&gt; …&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;True / False heuristic in Python
&lt;ul&gt;
&lt;li&gt;Nearly everything in Python is true&lt;/li&gt;
&lt;li&gt;except for &lt;code&gt;False&lt;/code&gt;, &lt;code&gt;None&lt;/code&gt;, &lt;code&gt;0&lt;/code&gt; or anything empty (empty lists, dictionaries, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Learnt how working with strings in reverse works
&lt;ul&gt;
&lt;li&gt;if I want the last element in a string, I could reference it by calculating it’s length and lopping one off (since indexes start at 0), like with the string &lt;code&gt;s = 'Halt! Who goes there?'&lt;/code&gt; I could access the last element by &lt;code&gt;s[len(s)-1]&lt;/code&gt; or the last but one, with a &lt;code&gt;s[len(s)-2]&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This is made a lot more convenient by just dropping the &lt;code&gt;len(s)&lt;/code&gt; stuff, just leaving the &lt;code&gt;- numeral&lt;/code&gt; part - &lt;code&gt;s[-1]&lt;/code&gt; or &lt;code&gt;s[-2]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;This makes so much sense in my head now, if what I am doing is counting straight and then subtracting one. I should remember, things sometimes are simpler than they seem :)&lt;br&gt;
For some reason, I always imagined, Python could see the length of my string, so why couldn’t there be a reverse string way of doing things like &lt;code&gt;s.rev[0]&lt;/code&gt; that would just count backwards 😂&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Strings are immutable. They can’t be changed. I can just process a copy and generate new ones, though.&lt;/li&gt;
&lt;li&gt;just realised that the f in f-strings stands for &lt;em&gt;formatted strings&lt;/em&gt;, since when I write raw strings, I use an r for, duh, &lt;em&gt;raw strings&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Slicing involves carving out a small contiguous part out of a larger string. The thing to note is that when I say &lt;code&gt;s[0:4]&lt;/code&gt; it means &lt;em&gt;upto, &lt;strong&gt;but not including&lt;/strong&gt; 4&lt;/em&gt;
&lt;ul&gt;
&lt;li&gt;If I say &lt;code&gt;s[0:100]&lt;/code&gt;, slices are forgiving and give me upto the end of my small string, without throwing an error.&lt;/li&gt;
&lt;li&gt;Empty colons in slices imply endings. &lt;code&gt;s[:10]&lt;/code&gt; means start from 0 and go up to 9. Or &lt;code&gt;s[9:]&lt;/code&gt; means start at 9 and go upto the end. Ergo &lt;code&gt;s[:]&lt;/code&gt; means from the beginning to the end.&lt;/li&gt;
&lt;li&gt;I can have step sizes to step over. The default, hidden size is 1. I can step, oh, say every three elements by append &lt;code&gt;:3&lt;/code&gt; to the end of my slice like so, &lt;code&gt;s[0:20:3]&lt;/code&gt;, basically [start&amp;#x1f51a;step size]&lt;/li&gt;
&lt;li&gt;I can also have negative step sizes which will give me the results in reverse. The most common one being -1, because the quickly reverses a string for me (commonly done). But it works with other step sizes too. A -2 will start counting backwards every other character from the end. A reverse slice begins with the end character and then beginning. So &lt;code&gt;s[10:5:-1]&lt;/code&gt; to carve out a slice backwards.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Sequences are strings, tuples and lists. They all can be sliced and diced and iterated upon.&lt;/li&gt;
&lt;li&gt;Heuristic, &lt;code&gt;else&lt;/code&gt; in a &lt;code&gt;for&lt;/code&gt; loop is to match stuff when I don’t encounter a &lt;code&gt;break&lt;/code&gt;. the &lt;code&gt;else&lt;/code&gt; part matches the &lt;code&gt;for&lt;/code&gt; to form the &lt;code&gt;for-else&lt;/code&gt; construct, even though the break is inside the for loop&lt;/li&gt;
&lt;li&gt;&lt;code&gt;while&lt;/code&gt; loops are for when you don’t know the end of what you are looking for. there is not finite end. No 0 - 10 happening. You are just searching for something in an amorphous swamp. The swamp is vast, there is no way to say from this end of the swamp to that end.You only give up when you find what you are looking for, or when you decide it’s time to give up (some preset condition).
&lt;ul&gt;
&lt;li&gt;make sure there is a counter that breaks stuff or I might loop forever&lt;/li&gt;
&lt;/ul&gt;
&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;Realising why Python notebooks are used. Very, very, very, handy to quickly write prose and code at the same time. It fits my mental model of programming perfectly!&lt;/li&gt;
&lt;li&gt;I keep thinking strings and characters are English and forget to quote them! The number of &lt;code&gt;NameErrors&lt;/code&gt; I get, is not funny.&lt;/li&gt;
&lt;li&gt;Thing that keeps biting me when I write &lt;code&gt;or&lt;/code&gt; statments. I should remember to say &lt;code&gt;if x='blah' or x='meh'&lt;/code&gt;. I keep writing &lt;code&gt;if x='blah' or 'meh'&lt;/code&gt;, &lt;em&gt;which is wrong.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;I keep using a lot of superfluous variables. I should be more intentful. Instead of just printing an expression, I tend to figure out the expression, assign to a variable and then print it. Good for building, probably bad for optimal use. But I won’t worry about it too much now. Just something to improve on in the long term.&lt;/li&gt;
&lt;li&gt;Reuven is a painstakingly methodical teacher. If he’s so good in his videos, I am jealous of folks attending his live classes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a href="https://janusworx.com/tags/pythonbasics/" &gt;Read all about my Python basics journey here&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>