Day 8: Python Syntax: Basic Concepts — Deep Dive String manipulations

Day 8: Python Syntax: Basic Concepts — Deep Dive String manipulations

image 39 Simply Creative Minds

String manipulation is an essential part of working with strings in Python. Below are some common string manipulations we can perform:

String Formatting

We can format strings using f-strings (available in Python 3.6+), .format(), or the % operator.

name = "John"
age = 25
formatted_string = f"My name is {name} and I am {age} years old."  
# Output: "My name is John and I am 25 years old."

formatted_string2 = "My name is {} and I am {} years old.".format(name, age)  
# Output: "My name is John and I am 25 years old."

Checking String Case 

(isupper()islower())

my_string = "HELLO"
is_upper = my_string.isupper()  
# Output: True

my_string = "hello"
is_lower = my_string.islower()  
# Output: True

Joining a List of Strings 

(join())

words = ["Hello", "World", "Python"]
joined_string = " ".join(words)  
# Output: "Hello World Python"

Testing for String Properties 

(isalnum()isalpha()isdigit(), etc.)

my_string = "Hello123"
is_alnum = my_string.isalnum() 
 # Output: True (contains letters and digits)

alpha_string = "Hello"
is_alpha = alpha_string.isalpha()  
# Output: True (only letters)

digit_string = "12345"
is_digit = digit_string.isdigit()  
# Output: True (only digits)

Happy Coding and Stay Tuned 🙂

Kind is always cool !!!

Share knowledge to gain knowledge !!!!

Be kind and treat people with respect !!!

If you find my blog helpful, then please subscribe, claps and follow to support 🙂

image 35 Simply Creative Minds

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *