In computer science, a string is a piece of text or a collection of characters.
A string can be stored in a variable, can be typed in by the end-user (input) or can be displayed on the screen (output).
In the above Python instruction: “Hello World” is a string. Notice the use of speech marks when using a string in code.
A string can be stored in a variable for instance.
greeting = "Hello" print(greeting)
The act of joining two strings together is called string concatenation.
In Python string concatenation is done using the + sign:
firstname = "James" print("Hello " + firstname)
String Manipulation Techniques
In computer programs it is often necessary to manipulate strings to:
- Extract or truncate the first few characters of a string,
- Extract or truncate some characters at the end of the string,
- Find out the length (number of characters) of a string,
- Convert a string from lowercase to UPPERCASE or vice-versa,
- Check if a character has been used in a string,
- Find out if a string contains a specific substring or word,
String Manipulation Challenges
Use our Block Programming tool to complete and test some String Manipulation challenges online.