Strings - 3.2.3

# Are an abstraction since it allows you to perform operations on multiple words and/or letters without seperating them individually
# Allows letters to be represented using language rather than numbers
firstName = "John"
lastName = "Doe"
laugh = "Ha"
fruit = "Watermelon"
fruitWithSpace = "   Watermelon   "

# Concatenation
print("Concatenation:")
print("First name and Last Name:", firstName + " " + lastName) #abstracts by allowing dynamic manipulation of strings
print("-"*50)

# Repetition
print("Repetition:")
print(laugh * 4) #abstracts having to use a loop to repeat the string
print("-"*50)

# Indexing String
print("Indexing:")
# 0 based indexing system
print(fruit[0:5]) #abstracts having to use a loop to iterate then manually obtain the first 4 letters
print("-"*50)

# Length of String
print("Length of String:")
print(len(firstName)) #abstracts having to count the letters manually or using more steps
print("-"*50)

# Change Letter Format
# prevents having to loops to manually change letter format based on condition
# otherwise would require checking through ASCII or other methods
print("Changing Letter Format:")
print(firstName.upper())
print(firstName.title())
print("-"*50)

# Strip
# Abstraction as a condition and loop is not required to identify spaces and remove them
print("Removing whitespace:")
print(fruitWithSpace.strip())

Concatenation:
First name and Last Name: John Doe
--------------------------------------------------
Repetition:
HaHaHaHa
--------------------------------------------------
Indexing:
Water
--------------------------------------------------
Length of String:
4
--------------------------------------------------
Changing Letter Format:
JOHN
John
--------------------------------------------------
Removing whitespace:
Watermelon

Javscript Version

%%js
let firstName = "John";
let lastName = "Doe";
let laugh = "Ha";
let fruit = "Watermelon";
let fruitWithSpace = "   Watermelon   ";


console.log("Concatenation:");
console.log("First name and Last Name:", firstName + " " + lastName); 
console.log("-".repeat(50));


console.log("Repetition:");
console.log(laugh.repeat(4)); 
console.log("-".repeat(50));


console.log("Indexing:");
console.log(fruit.slice(0, 5)); 
console.log("-".repeat(50));


console.log("Length of String:");
console.log(firstName.length); 
console.log("-".repeat(50));


console.log("Changing Letter Format:");
console.log(firstName.toUpperCase());
console.log(firstName[0].toUpperCase() + firstName.slice(1).toLowerCase());
console.log("-".repeat(50));


console.log("Removing whitespace:");
console.log(fruitWithSpace.trim());