Skip to main content

/docs/images/banner.jpg

Python

String operation

Implement a Python program that demonstrates 5 different string operations, such as concatenation, slicing, conversion, etc

# String concatenation
string1 = "Hello"
string2 = "World"
print(string1 + " " + string2)

# String slicing
string = "Hello World"
print(string[0:5])

# String conversion
string = "123"
print(int(string))

# String length
string = "Hello World"
print(len(string))

# String repetition
string = "Hello"
print(string * 3)

# Output:
# Hello World
# Hello
# 123
# 11
# HelloHelloHello

note

To compile and run the program, you can use the following commands:

python3 foo.py