String Variable in Python

A string is a group of characters.

A character is nothing more than a symbol. If you look at the English language, there are 26 characters.

It is not like characters are essential to computers. They deal with numbers instead (binary). If you look at your screen, you may see characters. But inside your computer, it is stored and used as a combination of 0s and 1s, not as characters.

Encoding is the process of changing a character into a number, and decoding is changing back. Many people use ASCII and Unicode to encode their text.

In Python, a string is a group of Unicode characters that can be read. Unicode was created to include every single character in every language and make encoding the same for all languages.

It is called a string because (funny story) when the early ancestors wanted to write, the first means of printing was using strings or ropes to create the symbols or characters.

For example, a string can draw adam and use the same rope they will dip in ink and press onto the page to create a cursive. So in Python, any combination of letters is called a string.

When writing a string in Python, you must use (single or double) quotation marks. You can even use triple quotes! That is generally used to represent multiline strings.

For instance, if you want to declare a variable for your name, you must put it in quotes. I will use my name as an example:

name = “Joe Biden”
name = ‘Joe Biden’

Both variables above are the same.

A string can have more than one letter or word. It can even be a full-blown sentence or a paragraph.

These are strings:

age = “four”
country = “America”
hobby = “I love Python programming”

The only rule is that you must be consistent with the kind of quote you use. If you start a string with a double quote, you must end it with double quotes and vice versa.

Do you want to become an expert programmer? See books helping our students, interns, and beginners in software companies today (Click here)!

Leave a Comment

Python Tutorials