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")
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
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
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"
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
Top comments (0)