String Characters

A string is a list of characters

senders_phone_number = "+4407973123456";
if (senders_phone_number[0] == '+')
Negative indices

Negative indices count backward from the end of the string, so string_name[-1] is the last character of the string, etc

Altering characters in a string

Strings are immutable in Python, so you can’t do this:

my_string[0] = 'a'    #<<This won't work!

you have to do this instead:

my_string = "a" + my_string[1:]

Work through each character in a string

for next_character in my_string:
  print(next_character)
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

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