• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Using Python to Append Character to String Variable

Using Python to Append Character to String Variable

July 26, 2022 Leave a Comment

To append a character to a string in Python, the easiest way is with the + operator.

string = "this is a string"
character = "."

string_appended = string + character

print(string_appended)

#Output:
this is a string.

When working with strings in Python, the ability to easily be able to modify the values of these variables is valuable.

One such case is if you want to append characters to a string variable and add characters at the end of the string.

To append a character to a string in Python, the easiest way is with the + operator. + concatenates two strings together and therefore we can use it to append a character to a string.

Below is an example showing you how to append a character to a string in Python with +.

string = "this is a string"
character = "."

string_appended = string + character

print(string_appended)

#Output:
this is a string.

How to Prepend Character to String in Python

If you want to add a character at the beginning of a string, instead of the end of a string, you can modify the example from above.

To prepend a character to a string variable, you can use + and switch the order from above.

Below is an example showing you how to prepend a character to a string in Python with +.

string = "this is a string"
character = "."

string_prepended = character + string

print(string_prepended)

#Output:
.this is a string

Hopefully this article has been useful for you to learn how to append a character to a string variable in Python.

Other Articles You'll Also Like:

  • 1.  Using Python to Find Closest Value in List
  • 2.  Using pandas to_csv() Function to Append to Existing CSV File
  • 3.  Using if in Python Lambda Expression
  • 4.  Get Quarter from Date in pandas DataFrame
  • 5.  Convert timedelta to Seconds in Python
  • 6.  Python atanh – Find Hyperbolic Arctangent of Number Using math.atanh()
  • 7.  Python Replace Space With Dash Using String replace() Function
  • 8.  Using Python to Insert Tab in String
  • 9.  Count Values by Key in Python Dictionary
  • 10.  Create Symbolic Link with Python os.symlink() Function

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy