Skip to main content

Python Basics for Testers: Variables, Data Types & Print Statements

 

πŸ“¦ 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 number 30.

✅ Rules for Variable Names:

  • Must start with a letter or underscore (_)

  • Can contain letters, numbers, and underscores

  • Case-sensitive (Name and name 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 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

Popular posts from this blog

Understanding XML for QA Testing

 As a QA tester, working with XML is essential, especially for API testing, data validation, and automation . Today, I explored the key concepts every QA should know about XML. πŸ”Ή What is XML? XML ( eXtensible Markup Language ) is used for storing and transporting data in a structured format. It’s widely used in APIs (SOAP), test data, and configurations . πŸ”Ή Why QA Testers Should Learn XML? ✅ API Testing – SOAP APIs use XML for requests & responses. ✅ Test Data Handling – XML is used in test scripts, Selenium, and data-driven testing. ✅ Config Files – Many automation tools (TestNG, Jenkins) use XML for setup. πŸ”Ή Key XML Concepts for QA πŸ“Œ XML Structure – Elements, attributes, nesting, and schema validation. πŸ“Œ XPath – Used for locating XML nodes in automation & API testing. πŸ“Œ XML Schema (XSD) – Ensures data correctness in APIs. πŸ“Œ Parsing XML – Reading & extracting values using tools like Postman, Python, or Java . πŸ’‘ Where to Learn XML? πŸ“– W3Scho...

30 Manual Testing interview questions from glass door

Here are 30 manual testing interview questions commonly encountered in interviews, compiled from various sources including Glassdoor: What is the difference between Quality Assurance (QA), Quality Control (QC), and Software Testing? QA focuses on improving the processes to deliver Quality Products. QC involves the activities that ensure the verification of a developed product. Software Testing is the process of evaluating a system to identify any gaps, errors, or missing requirements. Can you explain the Software Testing Life Cycle (STLC)? The STLC includes phases such as Requirement Analysis, Test Planning, Test Case Development, Environment Setup, Test Execution, and Test Closure. What is the difference between Smoke Testing and Sanity Testing? Smoke Testing is a preliminary test to check the basic functionality of the application. Sanity Testing is a subset of regression testing to verify that a specific section of the application is still worki...

QA Automation journey

πŸ”₯ 50-Day QA Automation Learning Plan (TS + Playwright) Day Topic Focus πŸ”Ή Phase 1: Foundations (Days 1–10) | 1 | Introduction to Test Automation & Testing Pyramid | What, why, and how of automation | | 2 | Intro to JavaScript & TypeScript | Setup, syntax overview | | 3 | Variables, Data Types, Constants | Hands-on coding | | 4 | Functions, Loops, Conditionals | Practice basic logic | | 5 | Classes & Constructors in TS | OOP basics | | 6 | Setup Playwright Project | Install, basic structure | | 7 | First Test with Playwright | Run test, understand selectors | | 8 | Debugging in Playwright | Logs, retries, timeout handling | | 9 | Folder Structure & Best Practices | Test organization | | 10 | Recap & Mini Project | Small Playwright test project | πŸ”Ή Phase 2: Unit & API Testing (Days 11–25) | 11 | What is Unit Testing? | Concept + console app example | | 12 | Annotations & Test Hooks | beforeAll, afterEach, etc. | | 13 | Parametrized...