I'm having trouble understanding how to work with nodes using python
Set the default_value of the input

There are many examples of this here, probable duplicate.  Here is an answer in lieu of a long comment

Set an input node value by altering its default_value property

import bpy
name = "Foo"
newmat = bpy.data.materials.new(name)
newmat.use_nodes = True
node_tree = newmat.node_tree
nodes = node_tree.nodes
bsdf = nodes.get("Principled BSDF")

bsdf.inputs[4].default_value = 0.9


Tip, for new material created as above can

&gt;&gt;&gt; bsdf, output = nodes
&gt;&gt;&gt; bsdf
bpy.data.materials['Foo.002'].node_tree.nodes["Principled BSDF"]


Testing in python console.

&gt;&gt;&gt; import bpy
&gt;&gt;&gt; name = "Foo"
&gt;&gt;&gt; newmat = bpy.data.materials.new(name)
&gt;&gt;&gt; newmat.use_nodes = True
&gt;&gt;&gt; node_tree = newmat.node_tree
&gt;&gt;&gt; nodes = node_tree.nodes
&gt;&gt;&gt; bsdf = nodes.get("Principled BSDF")
&gt;&gt;&gt; bsdf
bpy.data.materials['Foo.002'].node_tree.nodes["Principled BSDF"]

&gt;&gt;&gt; bsdf.inputs[4]
bpy.data.materials['Foo.002'].node_tree.nodes["Principled BSDF"].inputs[4]


Notice the input node is not a float

If we autocomplete the input node, will see its properties and member methods...

&gt;&gt;&gt; bsdf.inputs[4].
                   as_pointer(
                   bl_idname
                   bl_rna
                   bl_rna_get_subclass(
                   bl_rna_get_subclass_py(
                   default_value
                   display_shape
                   draw(
                   draw_color(
                   driver_add(
                   driver_remove(
                   ....