Strings are basically set of characters which can be enclosed by single or double quotes, like “hello”, “abc123” etc. If you ever need to deal with textual data, you’ll almost certainly need to work with it as a string object or a series of string objects. The string type, str, is a powerful, flexible means for  manipulating string data.

You can create strings by single quote:

Or double quotes:

And three times of double quotes:

You must close your string with same type of quote that you put at the beginning. This will give the following error:

You will get the same error if you try to print My father’s car. You should put this string into double quotes, like:

Other important thing is you can define a variable from string type then check the type of variable with type() command. Type will be str which means string for words and int / float for numbers. We will see numbers and basic mathematics operations later.

Here, as you see you do not have to put between quotes your variable. It’s interpreted automatically.

As strings formed from set of characters, they have their own position within a string. In “John” string; the place of j-o-h-n is called index. Index’s first position is always starts from 0 (zero). You can print an index from the beginning or end of a string. If you want to see last “n” character of “john” string type a[-1], to see all characters in the string use : sign,ex: a[:]

Look at this example:

Taking a part of a string is also possible. You can define from where you want to take this part, till which character and omission value.

General syntax is

[start index:end index:omission]

  • To see length of a string, we use len() function.

  • You can not modify directly a character of a string.

  • However, you can addition strings or append a new word into a string variable. Below, we will define a new variable.

  • Multiplication is allowed for strings