DEV Community

Cover image for [Part 2]Python Fundamentals: Syntax, Data Types, and Operators for QA
TestAmplify
TestAmplify

Posted on

[Part 2]Python Fundamentals: Syntax, Data Types, and Operators for QA

Introduction

Understanding Python fundamentals is essential for writing clean, maintainable, and efficient test scripts. This module introduces core concepts such as syntax rules, key data types, and operators used in test automation.


Lesson 1: Python Syntax Essentials

Concept:
Python relies on indentation and simplicity, making it beginner-friendly yet powerful.

Key Topics:

  • Indentation Instead of Braces: Consistent use of whitespace is critical.
  • Single-Line & Multi-Line Comments: Adding context to your test logic.
  • Basic File Structure: Writing executable .py scripts.

Example:

# This is a single-line comment
"""This is a
multi-line comment"""

if True:
    print("Test Passed")
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use 4 spaces per indentation level to maintain consistency.


Lesson 2: Core Data Types in Python

Concept:
Data types help define the nature of your variables and enable test script logic.

Key Topics:

  • Numeric Types: int, float
  • Text Type: str
  • Boolean Type: bool
  • Collection Types: list, tuple, dict, set

Example:

score = 95                 # int
percentage = 95.5          # float
status = True              # bool
name = "Login Test"        # str
results = ["Pass", "Fail"] # list
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use type() to check the data type of any variable.


Lesson 3: Operators in Python

Concept:
Operators are used for calculations and comparisons in automation logic.

Key Topics:

  • Arithmetic Operators: +, -, *, /, %
  • Comparison Operators: ==, !=, >, <, >=, <=
  • Logical Operators: and, or, not
  • Assignment Operators: =, +=, -=

Example:

actual = 100
expected = 100
print(actual == expected) # True
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use == for value comparison and is for identity comparison.


Lesson 4: Working with Strings in Python

Concept:
String operations are common in UI validation and log checks.

Key Topics:

  • Concatenation: Joining strings with +
  • String Formatting: Using f-strings or .format()
  • Slicing: Extracting substrings using [start:end]
  • Built-in Methods: upper(), lower(), replace(), strip(), split()

Example:

test_name = " login "
print(test_name.strip().capitalize()) # "Login"
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use f-strings for readable and efficient string formatting.


Conclusion

This module laid the foundation for writing Python automation scripts by covering the syntax, data types, and operators.

Key Takeaways:

  • Proper indentation is key to Python's syntax.
  • Know your data types to make logical decisions in tests.
  • Operators are essential for test validations.
  • String manipulation helps with assertions and data validation.

What’s Next?
In the next module, we’ll explore Control Flow and Decision Making in Python for QA Scripts, which will help you implement conditional logic and loops in your test scripts.

Visit us at Testamplify | X | Instagram | LinkedIn

Image description

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay