If the "Mindset of Decomposition" from our last lesson is the blueprint of your bot, then Variables and Data Types are the materials used to build it. In RPA, you are already used to setting variables like "OrderNumber" or "Price." In Python, we do the exact same thing, but with more power and precision. Understanding these "building blocks" is the secret to moving data seamlessly between a webpage and your final database.
Variables: Named Containers for Your Data
A Variable is simply a "label" for a piece of information stored in the computer's memory.
Syntax:
variable_name = valueThe "=" Sign: In programming,
=is the Assignment Operator, not a mathematical "equals." It means: "Take the value on the right and stuff it into the box on the left."
The RPA Connection: A Two-Way Street
In Octoparse AI, variables are your best friends. When you use the Execute Python Code command:
Input: Any variable you created in the RPA editor is automatically available as a Python variable with the same name.
Output: Any new variable you create or modify in your Python script can be sent back to the RPA workflow for later use.
Example:
order_id = "ORD12345" # Creating a new variable
count = count + 1 # Updating an existing variable
Data Types: The "Species" of Information
In Python, every piece of data belongs to a "Species" called a Data Type. The type determines what you can do with that data. (For example: You can subtract numbers, but you can't subtract words).
The Six Core Types for RPA Developers
Python Type | Key Features | Octoparse AI Equivalent |
String (str) | Text wrapped in quotes: "Alice". Used for names, URLs, or scraped text. | String Variable |
Integer (int) | Whole numbers: 100. Used for counting items or loops. | Number (Integer) |
Float (float) | Numbers with decimals: 29.99. Used for prices or precise measurements. | Number (Decimal) |
Boolean (bool) | Logical values: True or False. Used for "Yes/No" checks. | Boolean Variable |
List (list) | Ordered collections: ["A", "B"]. Used to store multiple items. | List Variable |
Dictionary (dict) | Key-Value pairs: {"id": "123"}. Used for structured data. | Dictionary Variable |
Why Type Matters: > If you add two Strings: "10" + "20", you get "1020".
If you add two Integers: 10 + 20, you get 30.
Python uses the Type to decide how to behave.
Basic Operations & Conversions
Once data is stored in a variable, you can manipulate it. Here are the most common actions you’ll perform inside an RPA Python node:
Joining Text:
full_name = first_name + " " + last_nameAdding to a List:
items.append("New Product")Accessing a Dictionary:
price = product["price"]
Type Conversion: The "Translator"
Often, data you scrape from a website comes in as a String, even if it looks like a number (e.g., "$99.99"). To do math, you must convert it:
int("100")→ Turns the text "100" into a real number100.str(100)→ Turns the number100back into text"100".
Summary: Your Data’s Identity
Variables carry your data, and Data Types define what that data can do. By mastering these, you ensure that your information flows correctly between your RPA steps and your custom Python logic.
Storing data is one thing; making decisions based on that data is another. In the next guide, we will teach your bot how to "think" and choose different paths based on the information it finds.
