- You want to retrieve the sheet IDs and sheet names in the Spreadsheet.
- You want to retrieve the sheet IDs of 40 sheets in the created Spreadsheet.
 
 
- You want to achieve this using gspread with python.
 
- You have already been able to get and put values for Spreadsheet using Sheets API.
 
If my understanding is correct, how about this answer? GID is the sheet ID of a sheet in a Spreadsheet. This is the same with the worksheet ID using at gspread.
In order to retrieve all worksheet IDs in a Spreadsheet, I think that the method of worksheets() can be used.
Sample script:
spreadsheetId = "###"  # Please set the Spreadsheet Id.
client = gspread.authorize(credentials)
sh = client.open_by_key(spreadsheetId)
worksheet_list = sh.worksheets()
for sheet in worksheet_list:
    print('sheetName: {}, sheetId(GID): {}'.format(sheet.title, sheet.id))
- In this script, it supposes that you have already used 
credentials. 
Reference:
If I misunderstood your question and this was not the direction you want, I apologize.