Split and join a string

In this program, we will take a string as input and split and join a string.

Steps to solve the program
  1. Take a string as input.
  2. Split the given string using Split().
  3. Join the splitter string using join() and ““.
  4. Print the output.
				
					#input string
string = "Hello world"

#Splitting the string
new_str = string.split(" ")
print(new_str)

#Joinin using -
print("-".join(new_str))
				
			

Output :

				
					['Hello', 'world']
Hello-world
				
			

remove a new line from a string

print floating numbers up to 3 decimal places and convert it to string.

Leave a Comment