Skip to content

Commit 7816084

Browse files
GCI105 StringConcatenation slight improvement in documentation
Co-authored-by: DataLabGroupe-CreditAgricole <[email protected]>
1 parent 51d9d62 commit 7816084

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/rules/GCI105/python/GCI105.asciidoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ city = "New York"
88
street = "5th Avenue"
99
zip_code = "10001"
1010
address = ""
11-
address += city + ", " + street + zip_code # Noncompliant: inefficient string concatenation
11+
address += city + ", " + street + ", " + zip_code # Noncompliant: inefficient string concatenation
1212
----
1313

1414
In this example, the `+=` operation creates a new string object for each concatenation. When done repeatedly (e.g., in loops), this leads to excessive memory allocations and slower performance.
@@ -20,7 +20,8 @@ In this example, the `+=` operation creates a new string object for each concate
2020
# Using f-string for readability and performance
2121
city = "New York"
2222
street = "5th Avenue"
23-
address = f"{city}, {street}"
23+
zip_code = "10001"
24+
address = f"{city}, {street}, {zip_code}"
2425
# or using str.join() for multiple string concatenations
2526
parts = ["New York", "5th Avenue", "10001"]
2627
address = ", ".join(parts)

0 commit comments

Comments
 (0)