upper / lower / title / strip / lstrip / rstrip / removeprefix / removesuffix / ljust /rjust / center
All of these are string methods are functions built into Python that allow us to perform specific operations on strings
If you're using VS Code, a BUNCH of things will pop up after you type in the dot!
We may also need to need to pass additional information to a METHOD, so we put that added info we put inside the parenthesis
upper
lower
title
lstrip
rstrip
strip
removeprefix
removesuffix
name.title()
It makes a string Title Case
First letter of each word is capitalized
name.upper()
This method will make everything UPPERCASE
name.lower()
This method will make everything UPPERCASE
Have a User type in a Famous String of text of text and store it in a variable
This could be a quote, passage, song lyric, etc...
First print the original string of text to the screen.
THEN, Print out the string in UPPERCASE, TITLE, and LOWERCASE making sure to tell the user which case they'll see
Example:
Run the program and make sure there are no errors.
THINK ABOUT THIS...
Out of all of these which do you think is the most important or useful? Why? Think Passwords
Any horizontal or vertical space in text is considered whitespace
Spaces
This is the most common type
Used to separate words and tokens
Tabs: ('\t')
Used to create horizontal tab space often for indentations
Typically equal to 4 spaces
Example Syntax:
"\tIndented Text - 4 Spaces = 1 Tab"
"\t\t\tReally Indented Text - 12 Spaces = 3 Tabs"
Notice there's no space between the \t and the written text
Newlines: ('\n')
Used to move the cursor to the beginning of the next line, creating a line break.
Example Syntax:
"Line1\nLine2\nLine3"
Looks Like:
"Line 1"
"Line 2"
"Line 3"
Note: NO spaces between the character and the text!!!
ALL OF THESE 6 ACTIVITIES CAN BE IN 1 FILE. HOWEVER, YOU MUST PRINT A BANNER BEFORE EACH ONE RUNS, SO I WILL SEE WHICH PROGRAM IT IS!
Write a program which prompts a user for their 4 favorite programming languages, and prints them like below
You MUST use Tabs and not SPACES no matter how you print this
In the same file, Prompt a user for 4 of their favorite foods
Display them as shown below
Write a program which prompts a user for their 4 favorite programming languages, and prints them like below
In the same file, now, using ONLY TABS, NEWLINES, and SPACES, add code which will print a simple table, looking like this:
Prompt a user to enter a FUN QUOTE from a person, author, etc...
Now, add code which will print a nicely formatted quote like below. It must display with quotes
HARD-CODE a quote from a person or author
HARD-CODE the person who said the quote
Add code so the program will print the formatted quote
Takes the front portion of a string off
Takes the back portion of a string off
mystring.removesuffix('thing_to_remove')
mystring.removeprefix('thing_to_remove')
my_name = "Mr. Severus Snape"
This Activity MUST be in it's OWN FILE: prefix-suffix.py
Gru needs a clean “Most-Wanted Domains” list for the Great Moon Heist. Your job: peel off every disguise a URL is wearing (protocols, www., slashes, crumbs) until you can shout the true lair name (the core website) into the AVL radio.
Create a variable holding a website name
Print out:
The Original Website
The website without .com
The website without https://
Create a Variable with the website name:
Print:
Original Website Provided
The Protocol used (https) - Gotta figure out how to get this from the site!
The name of the website only (Pokemon)
Scoreboard Mode:
Add section which will print a one-line explanation of what you removed at each step (e.g., “Removed https://”, “Removed .com”).
Do you remember time.sleep(1)?? Can you get this to work with the program???
TRY AND FORMAT THIS NICELY SO THE DISPLAY LOOKS COOL!! BONUS POINTS FOR THIS
Remove whitespace from right of string
Usage: string.rstrip()
Remove whitespace from left of string
Usage: string.lstrip()
Remove whitespace from right AND left side of the string
Usage: string.strip()
This Activity MUST be in it's OWN FILE: remove-whitespace.py
HOWEVER, YOU MUST PRINT A BANNER BEFORE EACH ONE RUNS, SO I WILL SEE WHICH PART IT IS!
The goal of this task is to help you understand how to manipulate strings in Python by removing extra spaces or tabs using three helpful string methods: strip(), lstrip(), and rstrip().
Add the strings above to your program
Print the strings as written so we can see what they look like with whitespace
Print all of the strings using the lstrip() method
Print all of the strings using the rstrip() method
Print all of the strings using the strip() method
You've been using some pretty weird alignment operations with FORMATTING in order to get your strings aligned like you want:
:< LEFT
:> RIGHT
:^ CENTER
*:^ PADDED
Left-aligns the string, padding it with the specified character (default is a space) to ensure it reaches the specified width.
Right-aligns the string, padding it with the specified character to reach the desired width.
Centers the string within a given width, padding it with the specified character,
This Activity MUST be in it's OWN FILE: minion-formatter.py
HOWEVER, YOU MUST PRINT A BANNER BEFORE EACH ONE RUNS, SO I WILL SEE WHICH PART IT IS!
Declare a Variable with a Minion Name
Declare a Padding Character
Declare a Width (number)
Output the name (with the padded character) as:
Left Justified
Right Justified
Centered
See if you can use the String Methods above to make a cool badge!
YOU'LL NEED BASIC MATH FOR THIS ONE!
This Activity MUST be in it's OWN FILE
HOWEVER, YOU MUST PRINT A BANNER BEFORE EACH ONE RUNS, SO I WILL SEE WHICH PART IT IS!
Create a small program that will output this....
It has:
Spaces
Tabs
Raw Strings
F-Strings
Unicode Characters
Newlines
Single quotes
TASKS:
You must get your screen's code to display as the example. You can use your own steps, plan location, names, etc... HAVE FUN AND BE CREATIVE WITH YOUR FORMATTING!!!
NOTE:
This must be formatted using tabs and alignment operations
You must user upper, lower, lstrip, rstrip, strip in the program
Your display should look organized!
You can use any string methods you know in order to help!!