#stringDemo.py #demo of basic stuff with strings: #variable, assignment, concatenation, input output, length/size. #textual, character data. A sequence of characters. #useful for names of people, places, things, events. Descriptions. IDs #string type for a string of characters. #a string constant is some characters within a pair of " or ' name = "joe" #assign a string to a variable print("Welcome:", name) #value of the string variable is output name = name + "smith" # + is string concatenation (sticking together one after the other) print("and now it's:", name) firstName = "Fred" lastName = "Smith" name = lastName + ", " + firstName #name = " " print("Welcome:", name) #a string can be the argument to the len function, which returns the length of the string print("this name has this many characters:", len(name)) #inputs all the characters (thus all the words) in the line up to newline: s = input("Enter a string of characters: ") print("You entered:", s, " It has", len(s), "characters in it.") # "" the null string (zero characters in it) len("") is 0 # " " a string of spaces print("hello" * 5) dog_talk = "bow wow " * 4 print(dog_talk) num_asterisks = int(input("Enter the number of *'s for a line:")) print('*' * num_asterisks) Methods. they don't change the variable s.strip() remove leading and trailing whitespace chars s.upper() convert to all uppercase s.lower() s.startwith('arf') True/False s.endswith('arf') s.find('arf') index where arf starts s.replace('arf','garp') all occurences "".join(aListOfStrings) glue them together ";".join(aListOfStrings) glue them together separated by ;