DataDriven
LearnPracticeInterviewDiscussDaily
HelpContactPrivacyTermsSecurityiOS App

© 2026 DataDriven

Loading lesson...

  1. Home
  2. Learn
  3. Strings: Beginner

Strings: Beginner

Text is everywhere in programming

Text is everywhere in programming

Category
Python
Difficulty
beginner
Duration
31 minutes
Challenges
0 hands-on challenges

Topics covered: What is a String?, Strings vs Numbers, String Concatenation, String Length with len(), Case Conversion

Lesson Sections

  1. What is a String? (concepts: pyStringBasic)

    A string is a sequence of characters. It can contain letters, numbers, spaces, punctuation, and special symbols. In Python, strings are created by enclosing text in quotes. Python does not care whether you use single quotes (') or double quotes ("). Both create the same type of string. Choose the style that makes your code more readable. Choosing Quote Styles The main advantage of having two quote styles is that you can include one type of quote inside a string wrapped with the other: If you nee

  2. Strings vs Numbers

    Trying to add a string and a number directly causes an error. See if you can spot and fix the bug below: Converting Between Types Use built-in functions to convert between strings and numbers: You can also convert strings to floating-point numbers and numbers back to strings:

  3. String Concatenation

    This prints "Maya Johnson". Notice we added a space " " between the names. Without it, we'd get "MayaJohnson". Building Complex Strings You can concatenate as many strings as needed to build formatted output: String Repetition The first line creates a string of 40 dashes. The second repeats "Hello! " three times. This is useful for creating visual separators or repeated patterns.

  4. String Length with len()

    This prints 13. The string has 13 characters: 5 letters in "Hello", a comma, a space, 5 letters in "World", and an exclamation mark. Empty Strings An empty string "" has length 0. It's a valid string that happens to contain no characters: The first prints 0. The second prints 3 because spaces count as characters. An empty string and a string of spaces are different! Practical Uses of len() This validates that a password has at least 8 characters. Length checking is essential for input validation

  5. Case Conversion

    Python provides methods to change the case of strings. These are essential for normalizing user input and performing case-insensitive comparisons. lower() and upper() This prints "hello, world!", then "HELLO, WORLD!", then the original "Hello, World!". The original string is unchanged because strings are immutable in Python. Other Case Methods Python provides several case-related methods for different formatting needs: Case-Insensitive Comparing A common use case is comparing strings regardless

Related

  • All Lessons
  • Practice Problems
  • Mock Interview Practice
  • Daily Challenges