Rotate your phone or change to desktop for better experience

Rotate your phone or change to desktop for better experience

8. Explore string functions

 str1 = "Hello, world!"

str2 = "I love Python."

str3 = "Hello, world!"

# compare str1 and str2

print(str1 == str2)

# compare str1 and str3

print(str1 == str3)

# using + operator

result = str1 + str2

print(result)

# count length of the string

print(len(str1))

print(len(str2))

# access character from 1st index to 3rd index

print(str1[1:4]) # "ell"

message = 'Hello world'

# assign new string to message variable

message = 'Welcome to Python Programming'

print(message) # Welcome to Python Programming

# iterating through str1 string

for letter in str1:

print(letter)

Post a Comment

0 Comments