connecting Mysql with Python code

connecting Mysql with Python code

Lesson Details:
June 29, 2020


I: Introduction

Before I start with my article on Python Programming language, I want to urge students who are reading this article to understand that the language is very new and does not require much explanation. Python is an open source language. It is also referred to as scripting language. As an open-source programming language, it is one of the most popular languages all over the world.

Python is used for developing various applications like games, web-based applications, networking software, bioinformatics, desktop applications etc. Basically, everything can be done using Python. It is said that Python is easy to read, learn and maintain. The syntax of python is simple and resembles english language. Python was first introduced by Guido van Rossum in 1991. It was named after Monty Python’s Flying Circus, a British comedy group. It was renamed as Python because it was difficult to pronounce.

There are two versions of Python; CPython and PyPy. CPython is the most common version of python which is used for general purpose programming. PyPy is a new version of python which is used for advanced programs. PyPy is the fastest version of python among other versions. Let’s see what are its features:

Features of Python:

1) Object Oriented Programming (OOP):

Python programming language supports OOP which makes it easier to manage data structures like lists, arrays, string etc. It supports multiple inheritance and allows programmers to define their own classes which are based on the parent class.

2) Dynamic Typing:

Unlike other languages, it does not have static typing feature. It means that the variables do not have an explicit type associated with them. This feature makes it simpler to write codes since there is no need to specify what type of data structure you are going to store in the variable. This feature also makes it easier for developers to modify code since they can change the variable data types without having to rewrite the whole code.

3) Exceptions:

The exceptions system allows users to handle errors or exceptions that occur during execution of a program by defining an exception handler which can be implemented using try-except block structure. The try block contains the execution of code while except block contains the recovery actions if any error occurs during execution of try block. This feature makes it easy for developers to make sure that the execution of program does not stop due to some error. The recovery actions also help in preventing unexpected termination of program.

4) Iterators:

Iterators feature allows developers to loop through the elements of a sequence or collection without having to use a counter or index variable. For example, if you want to iterate through the elements of a list then all you have to do is use for loop just like you would do in any other programming language such as C or Java.

5) Built-In Data Structures:

Python provides various built-in data structures such as lists, tuples, strings and dictionaries etc. These data structures are built into the language and don’t require any special effort from developer’s side to implement them. This makes it easier for programmers not only to save time but also hassles related with writing codes for these data structures individually. Let’s discuss how we can use these built-in structures:

Lists: Python provides lists, which are ordered collection of values that can be accessed using integer indexes (like array). You can add new elements at any position in the list and delete existing element from the list as well as retrieve element from list using integer index value. For example: x = [1, 2, 3] print(x[0]) // Displays 1 x[2] = 5 print(x) // Displays [1, 2, 5] Dictionaries: Python provides dictionary which is basically an unordered collection of key-value pairs where keys can be accessed using integer index and value can be retrieved using key value. For example: x = {'name': 'Mithun', 'coding': 'python'} print('Name = ', x['name']) // Displays Name = Mithun Strings: In python strings are immutable sequences that are enclosed with single or double quotes. You can access individual element of string using indexing operator and concatenate two strings together using + operator. For example: x = 'Welcome' y = 'to' z = x + y print(z) //Displays Welcome to Lists can be converted into strings using str() function but strings cannot be converted into list using same method. Dictionaries can be converted into list using dict() function but vice versa is not possible due to difference in nature of both types of data structure. Tuples: Similar to lists, tuples are ordered collection that cannot be modified once created unlike lists where element can be deleted or added at any position in the list. Tuples are enclosed with parentheses () and values are separated by comma (). Tuples can also be converted into a list by using list() function but vice versa is not possible due to difference in nature of both types of data structure. Integers: Integers are represented by four characters i.e 0-9 along with positive (+) and negative (-) sign which distinguishes them from other types of values like float, float, long etc. They can be used in various applications like games, networking etc. For example: x = 30 print(x) // Displays 30 Floats: Floats are represented by six characters i.e 0-9 along with . (dot), e (exponent), + (plus), - (minus), f (float), l (long) etc which helps developers differentiate floats from integers. Floats are useful when working with decimal values like currencies or percentages like 30% or 1234%. For example: x = 30 print(x) // Displays 30 Lacks: Lacks are represented by eight characters i.e 0-9 along with . (dot), e (exponent), + (plus), - (minus), f (float), l (long), B (binary), Q (hexadecimal), J (julian date), U (unsigned integer), X (hexadecimal). They are useful when working with non-decimal values like binary numbers or hexadecimal numbers like 1234B or 9r6QTu5X3E8F0UiBnJiRpiL2aH2uNDpkS1lONlDFTVLd3DVmZkh5MTVIxVmpJqNldjV2pGySStlBMl4hbW5uZXItYW1yQGZycHJvamVGaWxlKGNvbmZyYWNraW5uZXItYW1yLGZsdDpINldjRmRsZEJOMUpybndvbndvLGNvbmZyYWNraW5uZXItYW1yQGZycHJvamVGaWxlKS1mZXgtaGVhZGVyZXIiMThjMGJvamVGaWxlKGNvbmZyYWNraW5uZXItYW1yLGZsdDpINldjRmRsZEJOMUpybndvbndvLGNvbmZyYWNraW5uZXItYW1yQGZycHJvamVGaWxlKS1mZXgtaGVhZGVyZXIiMThjMGJvamVGaWxlKGNvbmZyYWNraW5uZXItYW1yLGZsdDpINldjRmRsZEJOMUpybndvbndvLGNvbmZyYWNraW5uZXItYW1yQGZycHJvamVGaWxlKS1mZXgtaGVhZGVyZXIiMTI2MnJhCHBsbCBsbDiBsbGFzdCBNaWR0aCBNaWR0aCBNaWR0aCBNaWR0aCBTaWNlOiBkcmlnaHQSE9TRzE9MzQzNzEyMDgzODA4NzA4NzZjNzZjNzZjNzZjODA4NzA4NzZjNzZjNzZjNzZjNzZ

loader
Course content