Python Variables in GRC: Difference between revisions
Jump to navigation
Jump to search
Mattcarrick (talk | contribs) No edit summary |
Mattcarrick (talk | contribs) No edit summary |
||
Line 5: | Line 5: | ||
The previous tutorial, [[Your First Flowgraph]], shows how to build your first simple flowgraph. The next tutorial, [[Variables in Flowgraphs]], describes how to use and modify variables in a more sophisticated flowgraph. | The previous tutorial, [[Your First Flowgraph]], shows how to build your first simple flowgraph. The next tutorial, [[Variables in Flowgraphs]], describes how to use and modify variables in a more sophisticated flowgraph. | ||
== | == Floats and Integers in GRC == | ||
GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point or integers: | GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point or integers: | ||
Line 20: | Line 20: | ||
doubleQuoteString = "string2"</pre> | doubleQuoteString = "string2"</pre> | ||
== Lists, Tuples and Arrays in GRC == | |||
Variables in GRC can also use lists and tuples: | |||
<pre>integerList = [1, 2, 3, 4, 5] | |||
floatList = [ | |||
* reference filter section that uses tuples to hold filter weights | * reference filter section that uses tuples to hold filter weights | ||
Line 27: | Line 34: | ||
== Using Python Types in GRC == | == Using Python Types in GRC == | ||
* python data types accepted in variables | * python data types accepted in variables | ||
== How GRC Displays Variable Values == | == How GRC Displays Variable Values == | ||
* 32,000 -> 32k | * 32,000 -> 32k |
Revision as of 20:44, 20 January 2022
This tutorial describes how Python data types are used in GRC and how the variables are displayed.
The previous tutorial, Your First Flowgraph, shows how to build your first simple flowgraph. The next tutorial, Variables in Flowgraphs, describes how to use and modify variables in a more sophisticated flowgraph.
Floats and Integers in GRC
GNU Radio Companion (GRC) uses Python data types to represent variables. The simplest data type are numbers. Numbers in Python can be floating point or integers:
floatNumber = 3.14 integerNumber = 2
Integers can be converted to floating point by casting using float(), and floating point numbers can be converted to integers using int():
floatNumber = float(2) integerNumber = int(3.14)
Python uses both single quotes ' and double quotes " to contain strings:
singleQuoteString = 'string1' doubleQuoteString = "string2"
Lists, Tuples and Arrays in GRC
Variables in GRC can also use lists and tuples:
integerList = [1, 2, 3, 4, 5] floatList = [ * reference filter section that uses tuples to hold filter weights * lists * arraysUsing Python Types in GRC
* python data types accepted in variablesHow GRC Displays Variable Values
* 32,000 -> 32k * 0.25 -> 250m The next tutorial, Variables in Flowgraphs, describes how to use and modify variables in a more sophisticated flowgraph.