π¦ 1. What is a Variable?
Think of a variable as a box that stores something for later use.
In Python, you don’t need to say what kind of data will go into the box. Just give it a name and assign a value.
π§ Syntax:
name = "Alice"
age = 30
π§ Explanation:
-
name
is a variable that holds the text"Alice"
. -
age
is a variable that holds the number30
.
✅ Rules for Variable Names:
-
Must start with a letter or underscore (
_
) -
Can contain letters, numbers, and underscores
-
Case-sensitive (
Name
andname
are different) -
Avoid using Python keywords (like
for
,if
,print
, etc.)
π’ 2. Data Types in Python
A data type tells Python what kind of value you're working with.
Here are the most common ones testers need:
π€ a. String (str
)
A string is a sequence of characters, like text.
city = "Tallinn"
Anything inside quotes (" "
or ' '
) is a string.
➕ You can join strings:
first = "Quality"
second = "Assurance"
result = first + " " + second
print(result) # Output: Quality Assurance
π’ b. Integer (int
)
An integer is a whole number — no decimals.
bugs_found = 5
π£ c. Float (float
)
A float is a number with a decimal point.
bug_rate = 2.5
❓ d. Boolean (bool
)
A boolean is either True
or False
.
is_test_passed = True
Useful for conditions like “Did this test pass?”
π️ e. List (list
)
A list stores multiple values in one variable.
test_cases = ["Login Test", "Signup Test", "Search Test"]
print(test_cases[0]) # Output: Login Test
Lists start at index 0
. You can store strings, numbers, or even other lists!
π️ f. Dictionary (dict
)
A dictionary stores data as key-value pairs.
bug = {
"id": 101,
"title": "Login fails",
"status": "Open"
}
print(bug["title"]) # Output: Login fails
Perfect for storing bug data or test case info.
π¨️ 3. Using Print Statements
The print()
function shows output on the screen.
Example:
print("Testing is fun!")
Output:
Testing is fun!
π Print Variables
You can print variables directly:
name = "Alice"
print(name)
Output:
Alice
π¬ Combine Text and Variables
Method 1: Comma ,
(most beginner-friendly)
tester = "Bob"
print("Tested by:", tester)
Output:
Tested by: Bob
Method 2: f-Strings (modern and clean)
age = 28
print(f"The tester is {age} years old.")
Output:
The tester is 28 years old.
✅ Why Testers Should Learn This?
Even if you're not writing full Python programs, knowing these basics helps you:
-
Read automation test scripts
-
Debug test failures
-
Modify test data
-
Build test input/output quickly
π§ͺ Small Practice Project: Bug Summary
Let’s combine what you learned into a tiny program.
π ️ Code:
bug_id = 101
bug_title = "Signup button not working"
severity = "High"
is_reproducible = True
print("Bug Report")
print("-----------")
print("ID:", bug_id)
print("Title:", bug_title)
print("Severity:", severity)
print("Reproducible?", is_reproducible)
π₯️ Output:
Bug Report
-----------
ID: 101
Title: Signup button not working
Severity: High
Reproducible? True
You just printed a bug report using variables, different data types, and print statements!
π€ Quick Recap
Concept | Example | Description |
---|---|---|
Variable | name = "Bob" |
Stores a value |
String (str ) |
"Login Failed" |
Text data |
Integer (int ) |
10 |
Whole number |
Float (float ) |
9.5 |
Decimal number |
Boolean (bool ) |
True , False |
Yes/No or On/Off |
List (list ) |
["TC1", "TC2"] |
Group of values |
Dictionary (dict ) |
{"id": 1, "status": "Open"} |
Key-value pair structure |
print("Hello!") |
Shows output |
π Final Thoughts
If you're starting your QA journey, Python is your friend. It's clean, beginner-friendly, and widely used in testing tools.
Today, you learned how to:
-
Store data in variables
-
Use common data types
-
Print anything to the screen
Next steps? Learn conditions, loops, and functions — they’ll help you write smarter test scripts or explore automation.
π‘ Bonus Tip for Testers
You can use Python to:
-
Generate random test data
-
Compare expected vs actual results
-
Read/write files (like test reports or logs)
-
Connect with tools like Selenium or APIs
That’s it for today’s Python basics! Start small, practice daily, and you’ll become comfortable with Python in no time.
Comments
Post a Comment