Found 10476 Articles for Python

Functional Programming in Python

AmitDiwan
Updated on 16-Sep-2022 12:03:59

1K+ Views

Functional programming languages are specially designed to handle symbolic computation and list processing applications. Functional programming is based on mathematical functions. Some of the popular functional programming languages include: Lisp, Python, Erlang, Haskell, Clojure, etc. Characteristics of Functional Programming The most prominent characteristics of functional programming are as follows − Functional programming languages are designed on the concept of mathematical functions that use conditional expressions and recursion to perform computation. Functional programming supports higher-order functions and lazy evaluation features. Like OOP, functional programming languages support popular concepts such as Abstraction, Encapsulation, Inheritance, and Polymorphism. Advantages of Functional Programming ... Read More

What does [::-1] do in Python?

AmitDiwan
Updated on 15-Sep-2022 14:28:57

22K+ Views

Slicing in Python gets a sub-string from a string. The slicing range is set as parameters i.e. start, stop and step. For slicing, the 1st index is 0. For negative indexing, to display the 1st element to last element in steps of 1 in reverse order, we use the [::-1]. The [::-1] reverses the order. In a similar way, we can slice strings like this. # slicing from index start to index stop-1 arr[start:stop] # slicing from index start to the end arr[start:] # slicing from the beginning to index stop - 1 arr[:stop] # slicing from ... Read More

What is slicing in Python?

AmitDiwan
Updated on 15-Sep-2022 14:22:36

2K+ Views

Slicing in Python gets a sub-string from a string. The slicing range is set as parameters i.e. start, stop and step. Syntax Let us see the syntax # slicing from index start to index stop-1 arr[start:stop] # slicing from index start to the end arr[start:] # slicing from the beginning to index stop - 1 arr[:stop] # slicing from the index start to index stop, by skipping step arr[start:stop:step] Slicing Example In his example we will slice a string from start, end, by skipping steps, etc − myStr = 'Hello! How are you?' print("String = ", ... Read More

What are the basic concepts of Python?

AmitDiwan
Updated on 15-Sep-2022 13:45:39

20K+ Views

Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. Features of Python Following are key features of Python − Python supports functional and structured programming methods as well as OOP. It can be used as a scripting language or can be compiled to byte-code for building large applications. It provides very high-level dynamic data types and supports dynamic type checking. It supports automatic garbage collection. Variables in Python Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Let’s create a variable. ... Read More

What type of language is python?

AmitDiwan
Updated on 15-Sep-2022 13:43:59

4K+ Views

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Let’s understand the paradigms one by one. Paradigms classify programming languages based on their features. Interpreted Language Python is processed at runtime by the interpreter. You do not need to compile your program before executing it. This is similar to PERL and PHP. Steps of Execution Step 1 − A Python source code is written by the coder. File extension: .py Step 2 − The Python source code a coder writes is compiled into python bytecode. In this process, a file with the extension .pyc gets created. Step 3 ... Read More

How are dataframes in Pandas merged?

AmitDiwan
Updated on 15-Sep-2022 13:43:21

303 Views

Pandas is an open-source Python Library providing high-performance data manipulation and analysis tool using its powerful data structures. A Data frame in Pandas is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. In this article, we will see how to merge dataframes in Python. We will use the merge() method. Following is the syntax: dataframe.merge(right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator, validate) Here, Parameter Value Description right A DataFrame or a Series to merge with how 'left' 'right' 'outer' 'inner': ... Read More

How to create an empty class in Python?

AmitDiwan
Updated on 15-Sep-2022 12:58:13

6K+ Views

A class in Python user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation. We can easily create an empty class in Python using the pass statement. This statement in Python do nothing. Let us see an example − Create an empty class Here, our class name is Amit − class Amit: pass Create an empty class with objects Example We can also create objects of an empty class and use it in ... Read More

What is _init_ in Python?

AmitDiwan
Updated on 15-Sep-2022 12:54:37

1K+ Views

The classes in Python have the __init__() function. This function gets executed when the class is being initiated. Let’s see some key points bout __init__ - The classes in Python have __init__() function. Similar to constructors in Java, the __init__() function executes when the object gets created. The __init__() function is called automatically. It is used to assign values to the properties of an object. The __init__() method may have arguments for flexibility. For that, the arguments given to the class instantiation operator are passed on to __init__(). When a class defines an __init__() method, class instantiation automatically invokes ... Read More

How to combine dataframes in Pandas?

AmitDiwan
Updated on 15-Sep-2022 12:52:38

811 Views

To combine dataframes in Pandas, we will show some examples. We can easily combine DataFrames or even Series in Pandas. Pandas is an open-source Python Library providing high-performance data manipulation and analysis tool using its powerful data structures. A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. Combine DataFrames using Inner Join Example Let us combine the dataframes using inner join in Python import pandas as pd # Create Dictionaries dct1 = {'Player':['Jacob', 'Steve', 'David', 'John', 'Kane'], 'Age':[29, 25, 31, 26, 27]} dct2 = {'Rank':[1, 2, 3, 4, ... Read More

Reverse the Rows of a Pandas Data Frame?

AmitDiwan
Updated on 15-Sep-2022 12:46:02

718 Views

We will see here how to reverse the rows of a Pandas Dataframe. Pandas is an open-source Python Library providing high-performance data manipulation and analysis tool using its powerful data structures. A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. Reverse the rows of a Pandas Data Frame using indexing Example In this example, we will reverse the rows of a dataframe using [::-1] − import pandas as pd # Create a Dictionary dct = {'Rank':[1, 2, 3, 4, 5], 'Points':[100, 87, 80, 70, 50]} # Create a ... Read More

Advertisements