Python Programming Tips


How to Connect to MySQL Database and Run Queries from Python

MySQL now provides support for pure python based access to mysql database. Use the python mysql connector in your program for accessing the mysql database. Run the following command in your machine’s command prompt to install the driver (this assumes you already have python3 installed), pip3 install mysql-connector-python If you get access denied error for […]

How to Run MongoDB Queries on Azure Cosmos DB Using Python

Azure Cosmos DB is a highly scalable and fully managed database service available on the Azure cloud platform. Using MongoDB API support, it is possible to store JSON documents in Azure Cosmos DB. If you are using Cosmos DB with MongoDB API support in your projects, sometimes you need quick Python scripts to analyse data. […]

How to Draw a Triangle in Python Turtle

Python has a simple pen drawing library called turtle. Using simple movement commands, we can draw shapes using the python turtle library. When teaching python to children, turtle is a good library to introduce to get children excited about the language and its features. The basic actions used in the following examples are, Draw a […]

How to Calculate SHA256 Hash of a File in Python

SHA256 is a secure hash algorithm which creates a fixed length one way string from any input data. The algorithm is designed in such a way that two different input will practically never lead to the same hash value. This property can be used to verify the integrity of the data. If data and hash […]

How to Calculate Average of Numbers in Python

The average or arithmetic mean of a collection of numbers is calculated by adding the numbers and then dividing it with the number of numbers in the collection. The arithmetic mean is used in almost all scientific disciplines for analysis. Consider the collection of numbers – 5,7,8,12. The arithmetic mean is (5+7+8+12)/4 = 8. There […]