What is unit testing?Unit testing is a type of software testing where each individual component of the system is tested. Unit testing is important practice for the developers. It ensures that every component of the software is functioning appropriately as expected. Unit testing is mainly performed by the developers during the coding phase of the software development.Unit testing makes it easy to fix the problems as the developers come to know which particular component of the system or software has the issues and the developers can fix that particular unit.Python Unit TestingThe python has an in-built package called unittest which is ... Read More
Insertion sort is the simple method of sorting an array. In this technique, the array is virtually split into the sorted and unsorted part. An element from unsorted part is picked and is placed at correct position in the sorted part.The array elements are traversed from 1 to n.If the array element at position i is greater than its predecessor, it does not need to be moved.If the array element at position i is less than its predecessor, it needs to be shifted towards left until we find a predecessor smaller than it or if we reach at the leftmost ... Read More
Most of the applications need to be integrated or connected with a database for performing certain relevant operations. The majority of projects require database connectivity to store certain data about the users. MySQL Database can be integrated with the Python applications.To connect MySQL database, we need to have it installed on our system. We need MySQL Connector to establish connection with the database. We can install MySql Connector using the following command.python –m pip install mysql-connector-pythonThis will install the MySQL Connector which is used to connect the python project or application to a database.Create a connectionFirst of all, it is ... Read More
There are two methods for converting a Deterministic Finite Automata (DFA) to Regular expression (RE). These methods are as follows −Arden's Theorem Method.State Elimination Method.Let us understand the Arden's Theorem method in detail.Arden's TheoremLet P and Q be the two regular expressions.If P does not contain null string, then the following equation in R, viz R = Q + RP, Which has a unique solution by R = QP*Here, The finite automata (FA) does not have epsilon moves.It must have only initial state q1.Its states are q1, q2, q3, ....qn. The final state may be some qi where iRead More
A text file is the file containing simple text. Python provides inbuilt functions to read, create and write text files. We will discuss how to read a text file in Python.There are three ways to read a text file in Python −read() − This method reads the entire file and returns a single string containing all the contents of the file .readline() − This method reads a single line from the file and returns it as string.readlines() − This method reads all the lines and return them as the list of strings.Read a file in PythonLet there be a text file named ... Read More
The UNION statement is used to combine the results of the two SELECT queries without repeating the duplicate values. If both the SELECT queries return same row, it is listed only once.To perform the UNION on two select statements, The number of columns returned must be sameThe datatypes of the columns must be sameThe columns must be returned in same order by both the select statements.SyntaxSELECT column_name FROM table1 UNION SELECT column_name FROM table2Steps to perform union of two select queries using MySQL in pythonimport MySQL connectorimport MySQL connectorestablish connection with the connector using connect()create the cursor object using cursor() ... Read More
The arithmetic operations as the name suggests are used to perform the operations such as additon, subtraction, division, multiplication or modulus.The arithmetic operations are operated on the numeric data in your table.SyntaxTo perform additionSELECT op1+op2 FROM table_nameHere, the op1 and op2 are the column names or the numeric values. If the op1 and op2 are the numeric values, then FROM clause are not required.The + in the above syntax can be replaced by -, *, %, / to perform other arithmetic operations.Steps to perform arithmetic operations in a table using MySQL in pythonimport MySQL connectorestablish connection with the connector using ... Read More
It may be sometimes required to add a new column in a existing table. Suppose we have a “Students” table with columns such as Name, Age, Roll no. We want to add a new column “Address” into our existing table.This can be done by using the ALTER command. The ALTER command is used to modify, drop or update columns in the database. This can also be used to add a new column into the table using ADD clause.SyntaxALTER TABLE table_name ADD new_column_name column_definition [FIRST | AFTER exisiting_column]Here, table_name refers to the name of the table, new_column_name refers to the name ... Read More
We may at times need to check if a particular record exists in a table or not.This can de done using the EXISTS statement. The EXISTS statement returns true if the following subquery returns one or more records.SyntaxSELECT * FROM table_name WHERE EXISTS(sub_query)The subquery if returns one or more rows, the EXISTS will return true.Steps to check if a record exists in a table using MySQL in pythonimport MySQL connectorestablish connection with the connector using connect()create the cursor object using cursor() methodcreate a query using the appropriate mysql statementsexecute the SQL query using execute() methodclose the connectionSuppose we have the ... Read More
We may sometimes require to get the list of all the tables present in our database. This can be done by using the SHOW TABLES command.The SHOW TABLES command is used to display the table names in a database as well as the server.SyntaxTo show the tables present in a database −SHOW TABLESThe above statement when executed using the cursor object returns the names of the tables present in our database.To show the tables present in a serverSELECT table_name FROM information_schema.tablesSteps to show all tables present in a database and server using MySQL in pythonimport MySQL connectorestablish connection with the ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP