parsing_data.rst
changeset 219 901b78003917
parent 197 97d859b70f51
equal deleted inserted replaced
215:3cd0facc1eb9 219:901b78003917
   202 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   202 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
   203 
   203 
   204 Hope you have enjoyed and found it useful.
   204 Hope you have enjoyed and found it useful.
   205 Thank you
   205 Thank you
   206  
   206  
       
   207 Questions
       
   208 =========
       
   209 
       
   210  1. How do you split the string "Guido;Rossum;Python" to get the words
       
   211 
       
   212    Answer: line.split(';')
       
   213 
       
   214  2. line.split() and line.split(' ') are same
       
   215 
       
   216    a. True
       
   217    #. False
       
   218 
       
   219    Answer: False
       
   220 
       
   221  3. What is the output of the following code::
       
   222 
       
   223       line = "Hello;;;World;;"
       
   224       sub_strs = line.split()
       
   225       print len(sub_strs)
       
   226 
       
   227     Answer: 5
       
   228 
       
   229  4. What is the output of "      Hello    World    ".strip()
       
   230 
       
   231    a. "Hello World"
       
   232    #. "Hello     World"
       
   233    #. "      Hello World"
       
   234    #. "Hello World     "
       
   235    
       
   236    Answer: "Hello    World"
       
   237 
       
   238  5. What does "It is a cold night".strip("It") produce
       
   239     Hint: Read the documentation of strip
       
   240 
       
   241    a. "is a cold night"
       
   242    #. " is a cold nigh" 
       
   243    #. "It is a cold nigh"
       
   244    #. "is a cold nigh"
       
   245 
       
   246    Answer: " is a cold nigh"
       
   247 
       
   248  6. What does int("20") produce
       
   249 
       
   250    a. "20"
       
   251    #. 20.0
       
   252    #. 20
       
   253    #. Error
       
   254 
       
   255    Answer: 20
       
   256 
       
   257  7. What does int("20.0") produce
       
   258 
       
   259    a. 20
       
   260    #. 20.0
       
   261    #. Error
       
   262    #. "20"
       
   263 
       
   264    Answer: Error
       
   265 
       
   266  8. What is the value of float(3/2)
       
   267 
       
   268    a. 1.0
       
   269    #. 1.5
       
   270    #. 1
       
   271    #. Error
       
   272 
       
   273    Answer: 1.0
       
   274 
       
   275  9. what doess float("3/2") produce
       
   276 
       
   277    a. 1.0
       
   278    #. 1.5
       
   279    #. 1
       
   280    #. Error
       
   281 
       
   282    Answer: Error
       
   283    
       
   284  10. See if there is a function available in pylab to calculate the mean
       
   285      Hint: Use tab completion
       
   286 
       
   287