≡ Menu

Python

9 Python if, if else, if elif Command Examples

Similar to other programming languages, in Python, conditional situations can be handled using if command. In this tutorial, we’ve explained the following with examples: Basic Python if Command Example for Numbers Python if Command Operators Basic Python if Command Example for String Comparison Multiple Commands in If Condition Block using Indentation Python if else Command [...]

{ 0 comments }

How to Connect to MySQL Database from Python With Example

From a Python program, you can connect to MySQL database to access the tables and manipulate your data. For this, you should use one of the Python MySQL Libraries. While there are few of these libraries available, the most popular and stable is mysql-connector-python library. The mysql-connector-python library uses APIs that are complaint with the [...]

{ 7 comments }

In the past few articles in the Python series, we’ve learned a lot about working with regular expressions in Python. In this article, we’ll explain how we could use python regular expressions for a realistic task. We’ll do a step by step walk through on how we can build Python data structures from formatted flat [...]

{ 3 comments }

This article is part of a series of articles on Python Regular Expressions. This article is a continuation on the topic and will build on what we’ve previously learned. In this article we’ll discuss: Working with Multi-line strings / matches Greedy vs. Non-Greedy matching Substitution using regular expressions In the first article of this series, [...]

{ 3 comments }

Regular expressions as a concept is not exclusive to Python at all. Python, however, does have some nuances when it come to working with regular expressions. This article is part of a series of articles on Python Regular Expressions. In the first article of this series, we will focus on discussing how we work with [...]

{ 15 comments }

A common idiom in programming is sorting a list. Python makes this a very simple task. Python provides a built-in sorted() function that accepts an iterable type, and return a sorted list: 1. Standard Sorting First, try sorting a list: >>> l = [3, 2, 5 ,4, 7, 1] >>> sorted(l) [1, 2, 3, 4, [...]

{ 15 comments }

Selecting and operating on a subset of items from a list or group is a very common idiom in programming. Python provides several built-in ways to do this task efficiently. Python Filtering 1. Python Filter Function The built-in filter() function operates on any iterable type (list, tuple, string, etc). It takes a function and an [...]

{ 11 comments }

An array is a data structure that stores values of same data type. In Python, this is the main difference between arrays and lists. While python lists can contain values corresponding to different data types, arrays in python can only contain values corresponding to same data type. In this tutorial, we will understand the Python [...]

{ 7 comments }