python-I-variable


Before diving into coding it’s important to assimilate few computer programming concepts like the one of a variable, which is a reserved memory location to store values. It gives data to the computer for processing. Each variable in python has its own datatype. In a script we have multiple variables, each one containing different memory to be processed.

The first line shows the python synthax to create a simple variable containing the text information. The second line contains a *function” print() which takes that variable and print its value in the console. If you want to see the content of variables you will have to use this function most of the time.

In grasshopper python it will look like this:

There you go your first script in GHPython!

Now, variable can also be copied. Note that in grasshopper the copy has been set as output in the component. Hence the variable is visible if you connect a pannel.

Variables in python must be written in a proper way. Some of the following naming will work but it is not considered very pitonish. Use only lower-snake-case for variables e.g. my_var, and capital-snake-case for constants e.g. CONST (variable that must not change value through out the script)

Let’s continue with the concept of primitive datatypes in python.