Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Using Python String Methods

Strings are the primary way that we interact with non-numerical data in programming, and the `str` type in Python provides us with a lot of powerful methods to make working with string data easier. In this hands-on lab, we'll be creating a script that can take a user-provided message and perform various actions on it before printing out those new results. To feel comfortable completing this lab you'll want to know how to do the following: * Utilize methods on the `str` class. Watch the "Using String Methods" from the Certified Entry-Level Python Programmer Certification course. * Working with list literals. Watch the "Lists" video from the Certified Entry-Level Python Programmer Certification course. * Using List functions and methods. Watch the "List Functions and Methods" video from the Certified Entry-Level Python Programmer Certification course.

Google Cloud Platform icon
Lab platform
Lab Info
Level
Beginner
Last updated
Sep 18, 2025
Duration
15m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Create the variations.py Script, Make It Executable with python3.7, and Accept User Input

    For variations.py, we're going to place it in our home directory (~) and we want to make sure that we can run it directly. To keep from being completely tied to the path of our python3.7 binary, we want to set up our shebang properly.

    Let's create the file and set the shebang:

    ~/variations.py

    #!/usr/bin/env python3.7
    
    # Python implementation here
    

    With the file created, we need to also make sure that it's executable and we can do this using chmod:

    $ chmod u+x ~/variations.py
    

    Next, we'll prompt the user for a message and store it off in a variable.

    ~/variations.py

    #!/usr/bin/env python3.7
    
    message = input("Enter a message: ")
    

    Now if we run the script (./variations.py) it should prompt us for a message, and then exit without any errors.

  2. Challenge

    Print the Lowercase, Uppercase, Title Case, and Capitalized Versions of the User's Input

    Now that we have the message variable, we're going to print a few different things to the screen:

    • The lowercase version using str.lower
    • The uppercase version using str.upper
    • The title case version using str.title
    • The capitalized version using str.capitalize

    Let's use each of these methods combined with the print function:

    ~/variations.py

    #!/usr/bin/env python3.7
    
    message = input("Enter a message: ")
    
    print("Lowercase:", message.lower())
    print("Uppercase:", message.upper())
    print("Capitalized:", message.capitalize())
    print("Title Case:", message.title())
    

    Now we can run the script to make sure that what we've written up to this point is working properly:

    $ ./variations.py
    Enter a message: This Is My Message
    Lowercase: this is my message
    Uppercase: THIS IS MY MESSAGE
    Capitalized: This is my message
    Title Case: This Is My Message
    
  3. Challenge

    Separate the String and Present the Individual Words as a List

    For the remaining requirements of our script, we need to work with the individual words. Because of this, we're going to store the words off as a new variable, words. We can get the words by using the str.split method. After we've separated the message into words, let's also print them out:

    ~/variations.py

    #!/usr/bin/env python3.7
    
    message = input("Enter a message: ")
    
    print("Lowercase:", message.lower())
    print("Uppercase:", message.upper())
    print("Capitalized:", message.capitalize())
    print("Title Case:", message.title())
    
    words = message.split()
    print("Words:", words)
    

    Here's the script running so far:

    $ ./variations.py
    Enter a message: This is a test Message!
    Lowercase: this is a test message!
    Uppercase: THIS IS A TEST MESSAGE!
    Capitalized: This is a test message!
    Title Case: This Is A Test Message!
    Words: ['This', 'is', 'a','test','Message!']
    
  4. Challenge

    Print the Alphabetic First and Last Words from the User's Input

    We're going to sort the words in the words list alphabetically and save the new list to sorted_words by using the sorted built-in function. Lastly, we'll print the alphabetic first and last words. Let's do this by indexing to 0 and -1.

    ~/variations.py

    #!/usr/bin/env python3.7
    
    message = input("Enter a message: ")
    
    print("Lowercase:", message.lower())
    print("Uppercase:", message.upper())
    print("Capitalized:", message.capitalize())
    print("Title Case:", message.title())
    
    words = message.split()
    print("Words:", words)
    
    sorted_words = sorted(words)
    print("Alphabetic First Word:", sorted_words[0])
    print("Alphabetic Last Word:", sorted_words[-1])
    

    Here's the final script running:

    $ ./variations.py
    Enter a message: This is a test message!
    Lowercase: this is a test message!
    Uppercase: THIS IS A TEST MESSAGE!
    Capitalized: This is a test message!
    Title Case: This Is A Test Message!
    Words: ['This', 'is', 'a','test','message!']
    Alphabetic First Word: This
    Alphabetic Last Word: test
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight