feat: more string manipulation
This commit is contained in:
5
src/modules/primitives/regex.py
Normal file
5
src/modules/primitives/regex.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
print("== Regular expressions ==")
|
||||||
@@ -24,7 +24,17 @@ def template_strings():
|
|||||||
print(f"{text=}, {field=}, {format_spec=}, {conversion=}")
|
print(f"{text=}, {field=}, {format_spec=}, {conversion=}")
|
||||||
|
|
||||||
# Allow input in templates
|
# 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():
|
def split_strings():
|
||||||
@@ -58,6 +68,15 @@ def split_strings():
|
|||||||
without_a = example_string.translate(no_a)
|
without_a = example_string.translate(no_a)
|
||||||
print(f"> Without a: {without_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():
|
def run():
|
||||||
|
|||||||
Reference in New Issue
Block a user