Like a guitar

--Originally published at Codebuster

Strings, strings, strings. Such a little word for the concept it holds. Strings are one of the most basic types on python, and therefore they make up a big part of any programmers’ life.

Strings literally mean a chain of characters, any variable that is text-based. It can be letters, words and even numbers. However, numbers in a string format are taken as labels, so you can’t do any mathematical operation with them.

In order to use strings you just need to do is declare it, and declaring it literally only takes quotation marks, as such:

string1= “Hello folks”

Even though they are pretty easy, you can do a number of things with strings, the simplest things you do with them are:

  • Measuring length: You can count how many characters are in a string, in a simple way:
    print len(string)
  • Adding two strings: If you ever want to add two strings, in order to creat a new string you just need to use the “+” symbol:
    NewString=string1+string2
  • Slice a string: Since strings are a number of characters strung together you can check a certain character in that string, for example:
    lastLetter= string[0]
  • Repeat a string: If you ever want to duplicate the string, all you need to use is the “*”:
    Doublestring: String*2