๐ ๐ Welcome to String Wonderland!#
๐ Strings at Drexel#
In Python strings are used for practical applications like:
Automating reports
Data analysis in research
Web development projects
Handling university data formats
๐งต What Are Strings?#
Strings are sequences of characters, like the digital textboxes of programming. Whether youโre storing words, symbols, or even emojis, Pythonโs strings have you covered!
๐ค Why Strings Matter?#
Strings allow us to work with textual data, enabling applications like:
Writing Python scripts for Drexel research labs
Analyzing survey responses
Building interactive course material
Managing student data in CSV and JSON formats
๐ String Basics#
In Python, strings are enclosed in single ('
) or double ("
) quotes.
drexel_motto = "Ambition Can't Wait"
college_name = "College of Engineering"
print(drexel_motto)
print(college_name)
Ambition Can't Wait
College of Engineering
๐ญ Multiline Strings#
Need more space? Use triple quotes ('''
or """
) for multiline strings.
drexel_vision = """Drexel is a university
where academic rigor meets real-world experience."""
print(drexel_vision)
Drexel is a university
where academic rigor meets real-world experience.
๐ String Operations#
Python makes string manipulation easy. Here are some basic operations:
Concatenation#
Combine strings using the +
operator.
school = "Drexel"
slogan = "Ambition Can't Wait"
message = school + " - " + slogan
print(message)
Drexel - Ambition Can't Wait
Repetition#
Repeat strings with the *
operator.
cheer = "Go Dragons! " * 3
print(cheer)
Go Dragons! Go Dragons! Go Dragons!
Accessing Characters#
Strings are indexable and immutable.
mascot = "Mario the Dragon"
print(mascot[0]) # First character
print(mascot[-1]) # Last character
M
n
๐ String Methods#
Python strings come with built-in methods for manipulation:
Change Case#
course = "Engr 131"
print(course.upper())
print(course.capitalize())
ENGR 131
Engr 131
Check Contents#
id_number = "12345678"
print(id_number.isdigit()) # True
print(id_number.isalpha()) # False
True
False
Replace Content#
phrase = "Hello, Drexel!"
print(phrase.replace("Drexel", "Dragons"))
Hello, Dragons!
๐ String Formatting at Drexel#
Python offers various ways to format strings. This is handy for generating dynamic content for Drexel use cases.
f-strings (Python 3.6+)#
student_name = "Alex"
course_code = "MEM 679"
print(f"{student_name} is enrolled in {course_code} this term.")
Alex is enrolled in MEM 679 this term.
.format()
Method#
template = "{} is part of the {} department."
print(template.format("Dr. Smith", "Mechanical Engineering"))
Dr. Smith is part of the Mechanical Engineering department.
๐ Advanced Techniques#
Slicing#
Extract substrings using slicing.
dept = "Mechanical Engineering"
print(dept[0:10]) # Mechanical
print(dept[-11:]) # Engineering
Mechanical
Engineering
Escape Sequences#
Add special characters with escape sequences.
escaped = 'The professor said, "Python is essential at Drexel!"'
print(escaped)
The professor said, "Python is essential at Drexel!"
Raw Strings#
Preserve raw content by prefixing with r
.
path = r"C:\Drexel\Projects\Python"
print(path)
C:\Drexel\Projects\Python
๐ String Applications in Research#
Strings are pivotal in data-driven research at Drexel:
Data Cleaning: Handle and clean messy CSV files from research.
Web Scraping: Extract data from websites using strings.
Natural Language Processing (NLP): Analyze text for insights in collaborative projects.
research_data = "Analyzing Drexel research trends!"
print(research_data.split()) # Breaks into a list of words
['Analyzing', 'Drexel', 'research', 'trends!']
๐ Data-Driven Projects#
In data science, strings help:
Parsing: Read and process CSV/JSON datasets.
Visualization: Add dynamic labels to charts.
Automation: Generate email templates for student communication.
# Example of a dynamic email
student_name = "Jordan"
course_name = "AI for Engineers"
email = f"Hello {student_name},\nYou are enrolled in {course_name} this term."
print(email)
Hello Jordan,
You are enrolled in AI for Engineers this term.