What are Strings in Python Programming?

Python is great at working with numbers, but what about when we want to communicate with people? To write programs that people can use, we need another variable type known as STRINGS.

Strings are what we call TEXT, or keyboard characters, in a programming language; they are groups (or ‘strings’) of letters, numbers, and symbols.

Your name is a string, as is your favourite colour.

A common way to use strings is in printing.

Let’s create a program that asks the user for their name, store their name in a variable called name, and then print their name on the screen 100 times!

SayMyName.py

What are strings in python proramming

There’s something new in the print() statement in the program’s last line: it contains a keyword argument. The keyword here is the ‘end’, and it tells the program to END each print() statement with a space (there’s a space between our quotes: “ “) instead of the regular end-of-line character.

With this end keyword argument we are telling Python we don’t want every printout of our name to be on a new line.

Strings in Python Programming

 

Related Article: Girls Who Code

Source: Teach Your Kids to Code: A Parent Friendly Guide to Python Programming by Bryson Payne, No Starch Press