Functions
Until now we wrote some code in and executed it line by line. For example we use following code to find the average price of 10 days stock price.
1 2 3 prices = [10, 20, 8, 9, 11, 20, 10, 12, 9 10] avg_price = sum(prices) / len(prices) print(f'Average price: {avg_price}') In the above example each line is executed one by one and finally the result is printed. What if we want to find the averge of another 5 prices?
Getting started with interpreter
3.1 Python Interactive Interpreter In the previous section, we saw how to install Python in various operating system. Now let’s learn how to use Python Interactive Interpreter and how to run a python program.
If you are using Windows open command prompt and type python. If you are using Mac, open Terminal and type python. open Console and type python in Linux.
This command opens Python interactive interpreter like the one shown below.
Installing Python
Introduction In this post we will learn about installing Python on Windows, Mac and Linux.
Windows Download python from https://www.python.org/downloads/. You will see multiple versions of Python listed over there. 3.7.1 is the latest stable version at the time of writing this post. Select 3.7.1 link as shown in the below figure.
After selecting a particular version of Python you will see all the platform specific setup files over there like the one below.
Python Introduction
Introduction Python is a general purpose programming language. First version of Python was released around the year 1991. Python syntax is inspired by C syntax, but it is much easier than that. If you are coming from other languages like C or Java, first thing you will notice that Python doesn’t use curly braces or semi colons. Even though Semi-colons are allowed, nobody really uses it.
Python is majorly used in following areas.
Thinking Pythonic
8.1 Introduction Until now, we have got introduced to Python, we have seen some data types and how to write loops like if, for and while. Before moving on, we will spend some time discussing about writing Pythonic code. What is a Pythonic code? Generally there are many ways to write a code that solves the same problem. But there will always be a best solution that is very specific to Python that is also elegant, beautiful, readable, and simple.