KELAS DATA SCRAPING
Kampus Remote Worker Indonesia | 2024
When working on data scraping tasks, string manipulation is crucial for cleaning and processing the extracted data.
print("We are learning Python string!")
1. f-strings
product = "Laptop" price = 999.99 text = f"Product: {product}, Price: ${"${price}"}" print(text) # Output: "Product: Laptop, Price: $999.99"
2. lower() / upper()
text = "Product Name" normalized_text = text.lower() # Convert to lowercase print(normalized_text) # Output: "product name"
3. strip()
text = " Product Name " cleaned_text = text.strip() # Removes leading and trailing spaces print(cleaned_text) # Output: "Product Name"
4. join()
words = ["Product", "Name"] full_text = " ".join(words) # Join with space print(full_text) # Output: "Product Name"
5. split()
text = "Price: $20.99" parts = text.split(": ") # Split by ": " print(parts[1]) # Output: "$20.99"
6. replace()
text = "$20.99" cleaned_text = text.replace("$", "") # Remove dollar sign print(cleaned_text) # Output: "20.99"
message = " Hello, world! How, are you today? " print(message)
Manipulate the current message to get the output hello-world!-how;-are-you-today?
hello-world!-how;-are-you-today?
Additional Finish this String Exercise!
Additional
Join us on this self-study journey! Click the link below to get started.
Master this advanced topic and supercharge your skills.
""" John Doe can be contacted via email at john.doe@example.com or call him at 8000-1234-4567 """
From this text, extract name, email, phone number in the dictionary.
Optional Try to solve one or more Strings Challenges.
Optional
Any Question?
<br>