DEV Community

still-purrfect
still-purrfect

Posted on

Strings in Programming: Working With Text Like a Pro

Everything you see on a screen messages, names, passwords, even emails is basically text.
In programming, that text is called a string.
So far, we’ve worked with numbers, logic, and repetition.
Now we move into something even more common in real applications: text data.
A string is simply a sequence of characters inside quotes.

name = "Mary"
print(name)
Enter fullscreen mode Exit fullscreen mode

🔹 Creating Strings

Strings can be written using either single or double quotes:

text1 = "Hello"
text2 = 'World'
Enter fullscreen mode Exit fullscreen mode

Both are valid. Just be consistent.

🔹 String Concatenation (Joining Text)

You can combine strings using the + operator.

first_name = "Mary"
last_name = "Akinyi"

print(first_name + " " + last_name)
Enter fullscreen mode Exit fullscreen mode

This joins the two strings into one full name.

🔹 Accessing Characters

Strings are like a sequence of letters. Each character has a position (index).

word = "Python"

print(word[0])
print(word[1])
Enter fullscreen mode Exit fullscreen mode

This prints:

  • P
  • y

Remember: indexing starts from 0.

🔹 String Length

You can find how long a string is using len().

word = "Python"
print(len(word))
Enter fullscreen mode Exit fullscreen mode

This returns the number of characters in the string.

💡 Why Strings Matter

Strings are everywhere in programming:

  • User names
  • Messages
  • Input from users
  • Website content
  • Passwords

Almost every application depends on text in some way.
Understanding strings gives you control over how programs communicate.

🌱 Challenge

Write a program that:

  • Takes a first name and last name
  • Combines them into a full name
  • Prints how many characters the full name has Try to think about how strings are used in real applications, not just the example.

Next, we’ll explore functions, where you learn how to organize your code into reusable blocks like a real developer.

Top comments (0)