Handling Text file in Python

Handling Text file in Python (Writing Data in Text file)

Storing data in text file is one of the important work people use to do in any language. If you will go for C++ and Java, you have to write lots of code for doing and making connection of stream explicitly and have to import many additional libraries to do so.

But here in case of python you no need to worry about all these. You have to write just few line of code to write data into text file. Here is the sample code.

 fout = open("StuTextFile.txt","a+")
name = input("Enter your name : ")
addr = input("Enter address : ")
school = input("Enter school : ")
str = name+"\t"+addr+"\t"+school

Code description –

In first line of code a file “StuTextFile.txt” will get open in append mode so that data entered will get saved again and again without overwriting it in to file. As you know default file mode is r+ to read, w+ for write and a+ to append.

Second, third and fourth line is just to get input from user (name, addr, school). Fifth line is creating a string with tab space. Sixth line is the important line to call write() function on the file object created (fout). Last line is to close the file object. It means file object’s connection with file will be disconnected.

LOC and Roll Number Allotted for CBSE Final Exam

LOC of Class Xth and XIIth with Roll Number – 2019

Finally yesterday on 16th January 2018 CBSE has published the list of students going to appear in Final Exam -2019 with their roll number and registration number. One problem here is that as earlier this year CBSE has not opened link to update students record at eleventh hour before practical exam. As you know the practical exam is scheduled between 15th January 2019 to 16th February 2019. To get your school LOC detail you can check below link.


Revised Date Sheet of Class XII Exam – 2019

Revised Date Sheet of XII Exam – 2019

CBSE has revised the date sheet of its final exam for one of the most important paper Computer Science (083) and Information Practices (065) from 28th March to 02nd April 2019. Where as the exam which was scheduled on 02nd April 2019 is now shifted to 04th April 2019.

The revised schedule is as per letter issued by CBSE letter.


Sample Papers

CBSE sample papers for class Xth and XIIth Exam

This is time to start putting focus on exam question paper patterns. As CBSE has announced the date of examination of its final exam which is going to get started from 15th of February 2019 and will get finished in last month of March 2019.

Here is the link to download sample question paper from the CBSE website. You can download it for class XII from – http://cbseacademic.nic.in/SQP_CLASSXII_2018_19.html

And for class Xth from the link – http://cbseacademic.nic.in/SQP_CLASSX_2018_19.html

Python Basic

Python Compound Data Types
(List, Tuple, Dictionary and String)

Python Compound data type are most powerful datatypes in compare to other languages. Python having four most important data types (List, Tuple, Dictionary and String). Lets start discussing it in brief.


List is the very first compound data type in python that can hold multiple values like array and indexed. Data will be enclose within square braces [] and separated by comma. The difference between normal array and list is- list can hold multiple value of multiple data type where as array can hold only same kind of data. For example –

lst = [4, ,6.7, ‘Hello”, ‘c’]

Here a list is declared with name lst and holding an integer, a float, a string and a single character.


Tuple s another compound data type in python that can hold multiple values and indexed. Like array or list but the elements of tuple is immutable (can not changed). Data will be enclose within parenthesis () and separated by comma. For example –

tpl= (4, ,6.7, ‘Hello”, ‘c’)

Here a Tuple is declared with name tpl and holding an integer, a float, a string and a single character.


A dictionary is a collection or compound data type which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.

dict = {'Name' :'Ramesh',
'age': 35,

Here a Dictionary is declared with name dict and holding key value pair of name, age, gender and marks.


String literal are the datatype which is most common and most useful. You can store a String in double quotes or singe quotes. String is indexed data type and mutable in place.

strdq = "I am String literal" #String with double quotes
strsq = 'I am String literal'  #String with single quotes 
print(strdq)     #print string in python 

Here a String is declared with strdq and strsq where strdq defined using double quotes and str sq defined using single quotes.