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?
Read more...

Python lists, tuples and sets

Introduction In this chapter we will learn about data types specific to Python language. They are lists, tuples, sets. We will also learn about dictionaries in next chapter. Lists Lists are simply collection of multiple objects. It can be a collection of integers, collection of strings and so on. A single list can also hold different type of objects. Let’s define a list 1 2 3 >>> basket = [] >>> basket = list() >>> basket = ['apple', 'orange', 'banana'] There are three ways to create a list.
Read more...

Simple data types

Introduction Like all programming languages, Python has variables as well. In this section we will learn about simple data types like integer, float, string and decimal. We will start with introducing variables. Variables Literally everything is an object in Python. For example, strings, numbers, True, False… etc. In real world most objects have a name. I have a name and you have a name. Likewise, in Python objects have name. In real world some object doesn’t have a name like a tree in you backyard.
Read more...

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.
Read more...

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.
Read more...

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.
Read more...

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.
Read more...

Django Introduction

Introduction Python’s CGI library is good enough for writing websites from ground up. But we need to put a lot of effort into it to build a usable and secure website. When building a web application we often come across some common tasks like authenticating users, connecting to a database, sending emails to users, a reliable admin interface to manage and add content to our site, etc. If we solve all of these problems ourselves, it is time-consuming.
Read more...

Web programming with Python - Django Introduction

Introduction Python’s CGI library is good enough for writing websites from ground up. But we need to put a lot of effort into it to build a usable and secure website. When building a web application we often come across some common tasks like authenticating users, connecting to a database, sending emails to users, a reliable admin interface to manage and add content to our site, etc. If we solve all of these problems ourselves, it is time-consuming.
Read more...

Deploying Django Application with Nginx and uwsgi

Introduction In this post we will learn about deploying Django applications. There are many ways to deploy a Django application. we can use either nginx or apache web server. Nginx is just a web server. It doesn’t know how to run Python programs. For this, we need a server which understands how to run python programs. This server is called application server. To run a application server, we can use uwsgi, gunicorn and etc.
Read more...