DEV Community

Cover image for How to Do String Manipulation in Python?
Ganesh Kumar
Ganesh Kumar

Posted on

How to Do String Manipulation in Python?

Hello, I'm Ganesh Kumar, and I'm building LiveReview — a blast-radius aware AI code review built for your business-critical systems. Star us to help devs discover the project, give it a try, and share your feedback to help improve the product.
Previously, we understood how each value is categorized into a data type.

We actually did some arithmetic calculations with the float and int data types.

Now, let's try to perform some operations on the string data type.

Performing String Concatenation and Replication

We can actually add two string values using the + operator.

'dev' + '.to'
dev.to
Enter fullscreen mode Exit fullscreen mode

Similarly, we can actually create multiple copies of a string value.

('dev' + '.to' + ' ') * 5
'dev.to dev.to dev.to dev.to dev.to '
Enter fullscreen mode Exit fullscreen mode

We can replicate a string using the multiplication operator.

Rules for Performing String Manipulation

We can't add a number directly to a string.

'dev.to' + 90
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    'dev.to' + 90
TypeError: can only concatenate str (not "int") to str
Enter fullscreen mode Exit fullscreen mode

Similarly, we can't perform subtraction or division operations on strings.

'dev.to' - '.to'
Traceback (most recent call last):
  File "<pyshell#58>", line 1, in <module>
    'dev.to' - '.to'
Traceback (most recent call last):
  File "<pyshell#58>", line 1, in <module>
    'dev.to' - '.to'
TypeError: unsupported operand type(s) for -: 'str' and 'str'

'dev.to' / '.to'
Traceback (most recent call last):
  File "<pyshell#59>", line 1, in <module>
    'dev.to' / '.to'
TypeError: unsupported operand type(s) for /: 'str' and 'str'
Enter fullscreen mode Exit fullscreen mode

There are some limitations, which we will get to know as we continue.

What's Next?

We have covered how values are managed and how we can manipulate them by following certain rules.

Now, we can actually combine these concepts into a code snippet.

I'm building LiveReview, a blast-radius aware AI code review built for your business-critical systems.

Instead of presenting every diff with equal emphasis, LiveReview scores each change by blast radius — how far its impact reaches through your call graph — so you can focus attention where it actually matters.

Spend code review effort where business risk is highest — not spread evenly across every diff.

⭐ Star it on GitHub:

GitHub logo HexmosTech / LiveReview

Blast-Radius Aware AI Code Review for Business-Critical Systems

LiveReview

gitleaks.yml osv-scanner.yml govulncheck.yml semgrep.yml dependabot-enabled mcp-testcases.yml

LiveReview: Blast-Radius Aware AI Code Review for Business-Critical Systems

LiveReview is an AI code reviewer that scores every hunk of a diff by blast radius: how far a change reaches through your call graph, how much persistent state it touches, and how well-tested it is. A 3-line change to a shared auth check can outrank a 300-line UI tweak. Your team's attention goes to the highest-risk code first, not spread evenly across every diff.

blast-radius-demo.mp4

LiveReview's Blast Radius & Review Priority scoring, live in the diff viewer.
















The exact math, not a black box Visualize blast radius at a glance Every factor that feeds the score

How does Blast Radius scoring work? (a more technical explanation)

Here's the goal:

  • A 3-line fix in a function used by 40 other files, that also writes to a database, should score high.
  • A 300-line UI change in one file, fully covered by…




Click below to try LiveReview with your codebase:

LiveReview Banner

Top comments (0)