≡ Menu

Python

12 Essential Python For Loop Command Examples

For loop is an essential aspect of any programming language. In python, for loop is very flexible and powerful. In this tutorial, we've explained the following Python for loop examples. Python For Loop for Numbers Python For Loop for Strings Python For Loop Using Default Range Function Python For Loop With Custom Start and End [...]

{ 4 comments }

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 [...]

{ 6 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: First, try sorting a list: >>> l = [3, 2, 5 ,4, 7, 1] >>> sorted(l) [1, 2, 3, 4, 5, 7] Next, [...]

{ 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. The built-in filter() function operates on any iterable type (list, tuple, string, etc). It takes a function and an iterable as arguments. filter() will invoke [...]

{ 11 comments }