Data processed by computers is often text. The datatype for text is known as STRING.
Here is a STRING stored in a variable in Python:
word = "Hello!"
Processing strings is what computers do a lot of! Python is a king at processing strings!
print(f"{word.lower()}") output = hello!
print(f"{word.upper()}") output = HELLO!
print(f"{word[0]}") output = h
print(f"{word[0:2]}") output = he
print(f"{word[3:]}") output = lo!
print(f"{word[-1]}") output = !
print(f"{word[-2:]}") output = o!
If you are not sure how these work, open your IDE and try it out!
first_name = "Alice"
last_name = "Johnson"
full_name = first_name + " " + last_name # Concatenation
print(full_name)
print("Hello! " * 3) # Output: Hello! Hello! Hello!
name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")
word = "hello"
print("a" in word) output = false
word = "hello-jack"
newWord = word.replace("-", " ")
print(newWord) output "hello jack"
Write a program that:
Enter your name: Alice Jones
HELLO, ALICE-JONES!
Create an email auto-correct tool:
Enter your email: Example@Email.COM
Valid email entered: example@email.com
Enter your email: Example.Email@COM
Invalid email!
Enter your email: wrongEmail.com
Invalid email!
datatype string uppercase lowercase length