Home - KeithChamberlain/PythonJourney GitHub Wiki
The roughest part of transitioning from R to python is the return
s. When I started with R I thought I had to return
everything from functions because that is what I saw other R programmers doing. It wasn't until the great Hadley Wickham corrected me at a conference course in front of a whole class (kindly, of course... Hadley is a gem!) in R in 2016 that I stopped using returns at the end of functions in R, as return() was for returning from a function early. So, literally, in R, if one uses return(obj) at the end of the function, they are returning from the function prematurely! Nothing like using R for 10 years prior to that and looking like a novice in front of a room full of experts because I developed a bad habit!
So I went into python keenly aware of returns() in R, and had the toughest time with the fact that returns (without parens in python) are important, because functions return
None
by default! Talk about getting off on the wrong 🦶! I spent the next week looking for ways to modify python so that instead of returning None
at the end of a function, if the return
was omitted, it would return
the last object. But alas, python doesn't print objects to the environemnt by default either... We have to use something like print()
. And what does print()
return other than... None
! So I'm back to return! Argh!
def returnsNone():
return print("Hello World")
print(type(returnsNone()))
<type: None>
Welcome to my python journey. The purpose of this Wiki is to document my process of learning python in such a way that anyone can go back and review. Hopefully the process is entertaining, so it is more like a archeological journal rather than a simple notebook. Stories will be included in order to keep the reader's attention. I want this to be more than a simple collection of code. Parallels with R will be drawn from time to time since that is the world I am coming from.
The Wiki is broken down into the following compact sections:
- Functions & keywords
- operators
- ternary operations [Massively Important!]
- lists
- strings
- for loops
- accumulators
- collectors
- sets
- tuples (pronounced "tup" (as in cup) "pull" 🤣)
- parallel lists
- dictionaries
- while loops