
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Updating Strings in Python
You can "update" an existing string by (re)assigning a variable to another string. The new value can be related to its previous value or to a completely different string altogether. For example −
Example
#!/usr/bin/python var1 = 'Hello World!' print "Updated String :- ", var1[:6] + 'Python'
Output
When the above code is executed, it produces the following result −
Updated String :- Hello Python
- Related Articles
- Updating Lists in Python
- Updating Tuples in Python
- Updating Dictionary in Python
- Updating data in MongoDB
- Buddy Strings in Python
- Updating boolean value in MySQL?
- Updating nested document in MongoDB
- Updating sub-object in MongoDB?
- How do I create an automatically updating GUI using Tkinter in Python?
- Program to find minimum deletions to make strings strings in Python
- Updating Nested Embedded Documents in MongoDB?
- Interesting facts about strings in Python
- Accessing Values of Strings in Python
- Removing strings from tuple in Python
- Python - Group contiguous strings in List

Advertisements