Logo F2FInterview

Python Advanced Interview Questions

Q   |   QA

We need to define a main function in which we query the database. The main() function will include a simple loop for iterating through the rows of the table as follows:

def main():
     for c in xrange(len(records)):
          fvalues = records[c]
          print fvalues
          if fvalues[0] == sys.argv[1]:
               print fvalues[1] 

Here we set up a for loop which runs from 1 (understood) to whatever the length of the table is. For each row, the entire row is read into 'fvalues'. If the first value in the row is equal to the string the program received from the user, the record is printed. 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: