Sample code to connect python with database

Connect Python with MySql

Python having feature to connect any of the database with the help of different database connection packages. Like to connect Python with MySql we can use mysql.connector package. Which can be downloaded from pip package of Python very easly. Here is the example of Python connection with MySQL.

import mysql.connector
mydb = mysql.connector.connect(

mycursor = mydb.cursor()
sql = “SELECT * FROM student”
myresult = mycursor.fetchall()

for x in myresult:

Here you need to import mysql.connector if already installed in your machine else you need to download and install using pip command. You can google it for installation process using pip. Once imported connector then you need to create connection using connect function by passing host, user, passwd and database name. Once the connection is ready you can call cursor and execute query on cursor. Once the function fetchall() called the result need to store in variable and at last iterate the result and get desire output. That’s it. You are done.

Fibonacci Series using recursion.

Fibonacci Series using recursion

In Python the Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. Here is the example of Fibonacii Series using Recursion in Python.

Fibonacii using Recursion in Python

Thank you, your comments are appreciated.

NVS Online Application for class IX admission-2020-21

NVS Online Application for class IX admission-2020-21

Navodaya Vidyalaya Samiti invites applications for admission in Class-IX against vacant seats in Jawahar Navodaya Vidyalayas for the session 2020-21. Online submission of applications starts from 25 October, 2019. Application may be submitted free of cost by accessing NVS website: (or)

  • Opening of online Window- 25.10.2019
  • Opening of online Window 25.10.2019
  • Date of Selection Test 08.02.2020

CBSE Sample Questions for Final Exam-2020

CBSE Sample Questions for Class Xth and XIIth

CBSE has given sample questions for class Xth and class XIIth final exam -2020 much before time expected in last week of September 2019. This year CBSE has changed question pattern for all the subjects. So this is very important to students and teachers to go through the sample paper given. Most of the common change across the subject what I found is that 20-30% questions are going to be objective type (one marks each) across all subject.

This will definitely going to make question paper yet conceptual. Because to solve these objective type you need to read whole book or syllabus properly. Now here is the link to get the question papers from CBSE Website.

Click here for Sample papers for class XII all subject

Click here for Sample papers for class X all subject

Hope you will get benefited with this information. Best of luck for your preparation for examination.

Class XIth Admission in Navodaya Vidyalaya


Hello class Xth passed out Students this is a Golden opportunity to take admission in class Eleven in Navodaya Vidyalaya of your District or any where you want to take admission. Last date to registration for phase I is extended till 15th June 2019 and for phase II 17th June 2019. URL for registration is –

Notification from Navodaya Vidyalaya Samiti

General features of Navodaya

  • Best Result in JEE MAIN- 2019: 38% Qualified from 11733 students
  • 873 & 8407 students qualified in JEE(advanced)-2018 and NEET-2018 respectively
  • 6 students from underprivileged class secured International admission after Class XII
  • Best results in Class X & XII Co-educational residential schools in every district of the Country
  • Separate hostels for boys and girls
  • Free education, Board and lodging
  • Wide cultural exchange through Migration Scheme Computer: Pupil Ratio-1:8

Criteria for Admission of Students to class-XI against vacant seats

  • Studied Class X in academic session 2018-19 in Govt./Govt. recognized school in the same District/State, where JNV is functioning and to which they are seeking admission.
  • Date of Birth of the candidate is between 1 June 2001 to 31 May 2005 (both days inclusive). This is applicable to all categories of candidates including those who belong to the Scheduled Castes and Scheduled Tribes
  • Admission against available vacancies in Class-XI on the basis of marks secured by students in Class-X Board Exam during the academic session 2018-19, subject to admission criteria of Navodaya Vidyalaya Samiti. Selection of students will be done as per the following steps:
  • District wise merit list will be prepared and students will be selected against the vacancies.
  • After selecting students against the vacancies in the JNV of the district, a common merit list will be prepared at State level.


Object Oriented Code in Python

Object Oriented Code in Python

This is time to go through the code to demonstrate the concept of OOP in Python. This is well known fact that OOP can not be done without Class and Object. So here is the example of Class and Object in Python.

Code of OOP in Python

Output of above code is –

Output of two Students Object

Now lets start understanding the code line by line. First line to Fourth line nothing but class level comment. Make it as clear and understandable as you can. Line no 8 is the beaning of class structure [class student(object): ]. It says that we are going start a class named Student and (object) is saying that this is new style of writing class and at last : is for starting the block statement. This is similar to { } sign in Java or C++

Next is [def __init__(self, name, marks):]. Here init is a function to initialise the object of class. If you are adding it well and good, if you left it don’t worry Python will insert it with default argument self on behalf of you. But here I used two extra parameters (name and marks), that means when ever user will try to create the object of Student class he/she have to pass these two parameters. After that and self.marks are two instance variables which are getting initialised by parameters of init method. Remember the style of writing init method, it starts with two underscore sing and ends with the same two underscore sign.

Now you can write N numbers of methods a per your business requirement. Remember that if the function takes self as parameter are instance method and will get called by the object directly. [def getStudent(self):] this is the only function we are heving right now.

Lastly we need to create object and call method associated with that. [s1 = student(‘Robin’, 98)] will create one object s1 of student class. As my init method takes two parameters except self. So need to pass. and lastly call getStudent() on s1. You will get output as above. I created two Objects, you can create as much as you want.

That’s it. You are done with basic example of Class and Object in Python. Comments and feedback are always welcome. Bye bye…

Basic Object Oriented Concept in Python

Object Oriented Concept in Python

Object oriented programming in Python is easy most then other OOP languages. Object oriented programming concept relates the programming to real world entities. You can reuse your code by creating multiple instance. Here import thing is to understand the concept of class and object.

Concept of Class and Object

Class – Classes are blueprint of real world situation, if you want to represent students details in terms of programming then you create a class named Student and add attributes to it as per your requirement like sname, fname, class, rollno, contactno, addr etc or any information that you want to get from Student.

Object – Objects are real instance of class created earlier (Student). You can create as much as object as per your requirement. Each object will have its own attribute associated and if you call the object you will able to get all the attributes detail associated with that object. Suppose rahul is the object of Student then rahul will carry all other infomations [sname-paul, fname-john, classs-9, addr- xyz colony]. Lets understand with code using Python in next post.

Exception Handling in Python

Exception Handling in Python

Exception handling is one of the important task which is covered in every language in many ways. Python also supports exception handling in their own way. Python exception handling is similar to Java exception handling. Like Java try – catch block python also having similar try – except block.

Any code that you that you think is going to throw exception must be written inside the try block. If exception occurs then the control will automatically transfer to except block and the code written in the except block will get executed. There are some predefined or built-in exception classes in python whose super class is Exception. The exception classes are –

  • FileNotFoundError
  • PermissionError
  • InterruptedError
  • NameError
  • OverflowError
  • RuntimeError

And many more similar exception classes are there for specify the error or exception in python. You can refer to Python Doc for more details of exception. But don’t worry you no need to worry about keep remembering the names of above exception classes. What you can do is to use Exception class which is super of all other exception class.

Next part of exception is throwing the exception as and when you want your code to through it. So for doing that if your remember Java we are having throw statement. In python we are having raise statement to throw specific exception from try block which will get cached by except block. Here is the example to demonstrate simple use of try-except block and exception handling in Python.

Code to demonstrate the use of Exception Handling

Output of the above programs are as follows –

Happy Scenario of code where no Exception

Exception Handling Scenario

The second output is from except block. If you want to contribute feel free to comment and give output.

JNVST Class 6th Result 2019

JNVST Class 6th Result 2019

Jawahar Navodaya Vidyalaya class 6th result of JNVST-2019 has been declared on Navodaya Vidyalaya Website. The result has been announced on web link below.


Now the big question is, how to login to the website? The website is going to ask login id and password. So the registration no will be the user name and password will be the date of birth of student appeared in the exam, suppose the students date of birth is 20th May 2009 then the password will be 20052009(DDMMYYYY) format without any / or – sign. Remember the date of birth in running will be the password to login to website. If some body is unable to login and get information from withe website. They can contact the Navodaya Vidyalaya of their district. Definitely school administration will help to get the result of the student. So go and get the result by clicking on above link. Best of luck for your result.

If you need any help, feel free to contact us or comment next to the post. We will try our level best to help you.

Bootstrap 3 vs Bootstrap 4

Bootstrap 3 vs Bootstrap 4 Differences

Twitter bootstrap 3 and bootstrap 4 both are very useful library for html based web page design. If some one is not so good in CSS and not much interested to work in webpage design. For them bootstrap is the best choice I developed many HTML and PHP base websites using twitter bootstrap 3. And very much happy with the look and feel of my websites. Second thing and which is very very important is Bootstrap is designed with the principal of “MOBILE FIRS”. So you no need to worry about how your website will look on tablets and mobile phones. It will automatically adjust your website based on screen size. This is really amazing.

Now lets start comparing bootstrap 3 and bootstrap 4 –

  1. Panel is dropped and Card is introduced in place. This is really helpful if you want to create look of grid in your website.
  2. Thumbnails are removed and introduced the same in image class.
  3. Glyphicons icon fonts are removed. So you can not use special icons like home, star, arrow, book, group, power button and many more. So what is the solution of this? You can use Font Awesome and similar kind of font. I love to use Font Awesome.
  4. Images class is changed as .image-responsive to .img-fluid, .img-rounded to .rounded and many more.
  5. Button default is renamed as .btn-secondary.
  6. Model component is re-written using fluid

Many more like these changes are introduced in Bootstrap 4. Once you will start exploring Bootstrap you will learn and will start loving it.

You can see my posts are using bootstrap and are very responsive. I can’t leave bootstrap until I get something more powerful tool like this.

You can add more value this post by commenting on it.