Iterate over words of a String in Python

String

In Python, strings are used to represent data which is in the form of characters, numbers, and symbols. The string is a collection of data that is represented in single(”) or double quotes(“”).To strings we can say array like other programming languages.

Examples:
str="hello"
str1="helloo123"
str2="Namaste@ india"

In above examples we show  different types of strings.First one is a alphabetic string , second one is the alphanumeric string.In aplhabetic string there is only alphabets and in aplhanumeric numbers with alphabets are there.

There are many functionalities and built-in-methode provided by python to work with strings.For iterate the string we have to split the string by in-built-methode spilt. split method splites the string by spaces . we have to store this splitted string in one variable . With the help of for loop we itrate the variable in which we stored the splitted string .

str= "Python is best programing language to learn"
    
print ("The string is : " + test_string) 
result= str.split() 
print ("/n The words of string are") 
for i in result: 
    print(i) 

 

Leave a Comment

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

Scroll to Top