How to append .L and .R to my vertex groups with script - AND maybe how to duplicate
There are three problems currently. 


You seem to have pasted the code into a text-editing programm with has encoded the script, then opened it up in Blender. Most likely the ending of your file was .rtf. As you can see in the text editor of Blender, this introduced numerous characters which we don't want. Right now your script starts with {\rtf\ansi ...
You have to simply open the text editor in Blender, paste the script directly, then press Run Script.
If you really want to edit your script externally, use the ending .txt or better .py (the python extension).
You have replaced the command startswith with beginswith (accidentally probably).
You are not using single quotes ', but other special characters ‘ and ’. The were probably generated by your text-editor as well. Use a simple texteditor instead, such as Blenders builtin text editor.


Here is the corrected script.

import bpy
obj = bpy.context.active_object

vg = obj.vertex_groups[:]
for g in vg:
    if g.name.startswith('b__R'):
        g.name = g.name+'.R'
    if g.name.startswith('b__L'):
        g.name = g.name+'.L'


However, I would suggest more changes.


Using the same script to toggle the ending on and off.
Comparing parts of the name with the slice notation.
E.g. to compare the first four characters: my_name[:4]
Replacing the ending letter with the fourth (fixed) L or R character.


These are a lot of obstacles for a beginner, here is the improved (changed) script, the benefit beeing to only need one.

import bpy

obj = bpy.context.active_object
for g in obj.vertex_groups:
    if g.name[:4] in ['b__R', 'b__L']:
        if g.name[-2:] in ['.R', '.L']:
            g.name = g.name[:-2]
        else:
            g.name = g.name + '.' + g.name[3:4]