print number and index of selected lines in text editor
import bpy

txt = bpy.data.texts['Text']
line_begin = txt.current_line_index

#select_end_line_index missing - iterate over txt.lines
for line_end, line_obj in enumerate(txt.lines):
    if line_obj == txt.select_end_line:
        break

selection = [i for i in range(line_begin, line_end + 1)]
print(selection)


There is already a comment function