
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

4K+ Views
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

26K+ Views
Python provides a python shell which is used to execute a single Python command and display the result. It is also called REPL. REPL stands for Read, Evaluate, Print and Loop. The command is read, then evaluated, afterwards the result is printed and looped back to read the next command.Sometimes after executing so many commands and getting haphazard output or having executed some unnecessary commands, we may need to clear the python shell. If the shell is not cleared, we will need to scroll the screen too many times which is inefficient. Thus, it is required to clear the python ... Read More

36K+ Views
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

64K+ Views
Graphs in Python can be plotted by using the Matplotlib library. Matplotlib library is mainly used for graph plotting.You need to install matplotlib before using it to plot graphs. Matplotlib is used to draw a simple line, bargraphs, histograms and piecharts. Inbuilt functions are available to draw all types of graphs in the matplotlib library.Plot a line in a graphWe will plot a simple line in a graph using matplotlib. The following steps are involved in plotting a line.Import matplotlibSpecify the x-coordinates and y-coordinates of the linePlot the specified points using specific function using .plot() functionName the x-axis and y-axis ... Read More

978 Views
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

18K+ Views
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

3K+ Views
It may be required to count the number of columns present in a SQL table.This is done using count(*) function with information_schema.columns and the WHERE clause. The WHERE clause is used to specify the name of the table whose columns are to be counted.SyntaxSELECT COUNT(*) FROM information_schema.columns WHERE table_name= ‘your_table_name’Steps to count columns 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 a table named “Students” as below −+----------+---------+-----------+------------+ | ... Read More

8K+ Views
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

5K+ Views
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

695 Views
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