Python is a multi-paradigm programming language. It supports different programming paradigms like procedural programming, object-oriented programming and functional programming. In this article we will understand the basic concepts of functional programming.
Functional programming is a programming paradigm, a style to organize our code. Separation of data and functions is the main idea of functional programming. Where data is to be acted upon and functions will act or determine what to do.
In functional programming, we write the code in pure mathematical function style.
Though we can implement our own sorting algorithm to sort items but using the built-in functionalities can be more efficient. In Python we have the
sort() method and the
sorted() function for sorting.
sort() only works for sorting lists.
sorted() function is more versatile as we can use it to sort other data types and objects. Today we will see how to sort lists, tuples and dictionaries using the
To sort a list we can either use the
sort() method or the
sorted() function. The
sort() method sorts a list in-place. That means
sort() will change the original…
In Python everything is considered as an object. Some of them are mutable and some of them are immutable. As we go further in our Python journey understanding the fundamentals like this becomes very important.
“An immutable object(unchangeable object) is an object whose state cannot be modified after it is created. This is in contrast to a mutable object (changeable object), which can be modified after it is created “— From Wikipedia.
So we can change mutable objects but can’t change immutable objects. But what does it actually mean? …
We can make some awesome design for our website using only CSS. In this article I will show you how we can make a profile card with some cool hover effects. Let’s get started.
Inside our project folder we need one HTML file, one CSS file and a folder to store profile image.
Opening a GitHub account is fairly easy. Just go to github.com, hit sign up and create an account.
To install git on you windows…
A Python set is a collection of unordered data with no duplicate values. Like a list a set is also a sequence of data. But unlike a list a set can’t have duplicate elements in it.
A set is an unordered collection with no duplicate elements — definition of a set from Python documentation.
Python sets are same as mathematical sets and support operations of mathematical set theory like intersection and union. But it is not required to be a pro in set theory to understand Python sets!
In this article we will see how to create a set and…
Decorators allow us to add more functionalities in a Python function. It is called metaprogramming because one part of the program adds something to another part of the program at compile time.
A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate. — Datacamp’s definition of a decorator.
Decorators are used on top of a function and starts with @ sign. Following is the basic structure to use a decorator:
For my web development project I needed to convert a bunch of images from JPG to PNG format. It was a hectic process to do it one by one manually. Then I found a solution on the web. Why don’t I just write a Python script to do it for me. So I did just that. Now I will show you how to do it with just few lines of Python code.
The idea is to give a target directory where images with JPG format will live. The program will convert all images from this directory to PNG format. Then…
We often exchange data through text files between our programs. Maybe we need to load data from a database. Maybe we need to generate a large amount of data in our program and save them. CSV is one of the most common and popular file format to exchange data between programs.
Python has built-in
csv module to work with CSV files. This module provides us functions to work with CSV files easily.
The word CSV stands for “comma-separated values”. A CSV file is a simplified spreadsheet stored as plaintext. The structure of a CSV file is as straightforward as its…
Undergraduate CS student | Passionate about programming and tech