From cc4267597ed87bbdd84b6225aeeb6053a62095a6 Mon Sep 17 00:00:00 2001 From: Daniel Heras Quesada Date: Sun, 23 Aug 2026 22:45:34 +0200 Subject: [PATCH] feat: more string manipulation --- src/modules/primitives/regex.py | 5 +++++ src/modules/primitives/strings.py | 21 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/modules/primitives/regex.py diff --git a/src/modules/primitives/regex.py b/src/modules/primitives/regex.py new file mode 100644 index 0000000..6dbec99 --- /dev/null +++ b/src/modules/primitives/regex.py @@ -0,0 +1,5 @@ +import re + + +def run(): + print("== Regular expressions ==") diff --git a/src/modules/primitives/strings.py b/src/modules/primitives/strings.py index 4dd3528..1cddea5 100644 --- a/src/modules/primitives/strings.py +++ b/src/modules/primitives/strings.py @@ -24,7 +24,17 @@ def template_strings(): print(f"{text=}, {field=}, {format_spec=}, {conversion=}") # Allow input in templates - # print(t"Hello, {input("Enter your name: ")} 👋 Welcome back!") + # These are only used to properly manage templates on code, such as library imput for better validation + # they keep track of what is dynamic and whats not + # that makes them useful for db query validation or user input validation + # template_str = t"Hello, {input("Enter your name: ")} 👋 Welcome back!" + # food = "cheese" + # template = t"Tasty {food}!" + # for part in template: + # if isinstance(part, str): + # print("String part:", part) + # else: + # print("Interpolation part:", part.value) def split_strings(): @@ -58,6 +68,15 @@ def split_strings(): without_a = example_string.translate(no_a) print(f"> Without a: {without_a}") + split_at_half_first = example_string[:(len(example_string) // 2)] + split_at_half_second = example_string[example_string.__len__() // 2:] + print(f"Split at half: [first] {split_at_half_first} [second] {split_at_half_second}") + + removed_the_second = example_string[:2] + example_string[3:] + print(f"Removed the second: {removed_the_second}") + + begin_inclusive_not_end = example_string[1:2] + print(f"Inclusive test: {begin_inclusive_not_end}") def run():