Python — A Journey from being a Beginner to an Expert — part 1

Python interpreter takes each line of code, interprets & executes it.Now, let’s use Jupyter Notebook (IDE) to write our first “Hello Word” in Python.Just, go to terminal or command prompt or if you have the shortcut to Jupyter notebook and fire that up..I am using terminal to start the notebook..Just type jupyter notebookIt opens up an interactive editor to write Python codes..I created a folder called Python-1 where I am going to write the codes..This is how it looks like.You can see a simple syntax which prints “Hello World”..So, what we will do is start with Functions and in its context we will learn the basics of Python.First we define a function and then we call it..The output is also shown.Now let’s pass an input argument to a function and see the output.So, far my function was printing out things using print statement..Now let the function return some value..Say we want to compute cube of a number.Now before we proceed making our function more involved, let’s see below some behaviors of the function-Here, in the first piece of code the function doesn’t have a return statement, it only prints the value..So, when we call the function within a print() statement the function prints it (from the definition) but because it doesn’t return anything, so it prints “None” as well which is a datatype in Python.However, in the second piece of code, the function has a return statement..So, calling it within the print() only returns the computer value.Now, let’s try to default a value for an argument in a function..Say we want to compute a power of any integer value at the same time by-default we want to compute unit power (1th power) of that integer.Here, in the first example, we just provide one value which Python understands for “n” as “x” is defaulted to 1.. More details

Leave a Reply