Skip to main content

Posts

Showing posts with the label Django with Python 3

Introduction to Django framework Part 14

 Introduction to Django framework Table of content What is web framework Django  Django features  Flask vs Django  Django setup and installation Create a django project Register an app and run the project What is web framework A web framework is a collection of modules, packages and libraries to speed-up the web development. Django Django is a Python Web framework. It follows MVT Design Pattern. M stands for Model which deals with data accces layer. T stands for template engine which represents the presentation layer and View is the controller that holds the business logic of the application.   Django features:   1. Rapid development - easy to setup and build a new project. 2. Django provides different components like authentication, model, modelforms, etc, which helps in development 3. Security - Django provides features to secure the project. 4. Scalability - Django applications are highly scalable. Other Python Web Frameworks Cherry pie Web2Py Pyramid Us...

Functional Programming in Python 3 - part 12

 Functional Programming in Python 3 - part 12 Table of content Functional programming Pure function Recursion Variables in immutable First class function Built-in high order function map function filter function Lambda Expressions Functional Programming Functional programming is a style of programming where almost every operation is performed with the help of functions. Functions are considered as first class citizens. Below are some of the guidelines for functional programming in python. 1. Pure Function : Every function is pure i.e. their behavior do not change for the same input. A pure function gives a consistent output (same output every time for the same input).  The arguments passed to the function should not be modified. Below example illustrate the pure function implementation. A function takes string as argument and returns its lowercase version without modifying the passed object.   def pure_fun(input_string): new_string = input_string.lower() # do not m...

Python 3 Part 11 - Access specifier in Python 3 classes

Access specifier in Python 3 classes  Table of content  Access specifiers Public Private Protected Special methods Access specifiers There are three access specifier/modifiers 1. Public : By default the functions and the variables are all public in python. Note: If there is no preceding _(Single underscore) or __ (Double underscore)   class MyClass: class_variable = 10 #public variable def my_method(self): print( "I am public method" ) obj1 = MyClass() obj2 = MyClass() print(obj1.class_variable) print(obj2.class_variable) obj1.my_method() obj2.my_method()   Output   $ python3 public_accessor.py 10 10 I am public method I am public method $   2. Private To define variable or method private to particular class we use __(Double UnderScore). Private members of class are only accessible within class. (Not in child class also)   class MyClass: __class_variable = 10 # private variable declared using double underscore def __my...

Python 3 Part 10 - Object Oriented Programming in Python 3

Object Oriented Programming in Python 3   Table of content  Class Types of variables Types of methods Namespaces Reusing code Association Inner class Single level inheritance Multi level inheritance Multiple inheritance Constructor overloading Class overloading  Interfaces Class Class is blueprint or design. Class has attributes called data members and methods also known as behavior. By default the class data members and methods are public in Python class. Syntax to define a class in python is                class <ClassName>:                     <body>                     .                     .                     . Below example is a class Computer.    class Comput...