In this chapter, I'm going to go through problems and solutions in Python. So the first section of this chapter would be about problems related to text and strings. The contents of this chapter would be texts related problems, solutions and examples. In the first section, I'm going to go through certain problems related to basics of string, concatenation, and so on. So the first problem would be about string concatenation and throwing concatenation is a process of joining characters end to end. For example, the concatenation of the term snow and the term ball is snowball.
The problem here is that you want to build strings up from a number of smaller strings or sub strings. To solve this problem, you would need to use an operator called plus sign operator consider having a variable called name one containing a text like Frank and another variable called name t containing a nother term or string called Stein. If you want to concatenate this and show it in the same time, you would use print function, then the concatenation of the two. So you would say print, open close parentheses, name one plus name two, and it will show you Frankenstein, which is the combination of Frankenstein. The second problem about concatenation is multiple concatenation here, the problem is that you want to show a strength multiple times. If you want to show the content of the first variable five times you would multiply it by the number five, and it will show you the term Frank five times.
The third problem is concatenation with Nin string values Sometimes you want to show a string with a number, and the number should be converted into a string. So the problem here is that you want to concatenate a string with a variable containing integer values or float values. So the variable that contains number is my num here contains the number 53. And that your text is score equals inside a variable called my text. To solve this problem, you would use the function str, which is short for strength, and it converts the number into a string. The result of this operation is score equals 53.
If you want to compare strings, you would use string comparison operator, the comparison operator is two equal signs. So if you want to compare two strings together, you would first have to have variables containing your name For instance, I have first name as my name Chad, and the last name, my last name are and if I want to compare them, I can use an if statement. So if the first name is equal to the last name, print something else print something else. So we print the two strings or the two texts are equal. Else, the two strings are not equal. Here, the first name is not equal to the last name and it should return the text that is inside the print statement of the else statement.
So it should say the two strings are not equal because they are not equal. That's how you use string comparison. If you want to search for substrings you can use in operator here, the in operator goes through a string that is assigned to a variable called my str. And we are going to search for a substring. called is it's a text is. So we search for is inside this line of text.
So this is a line of text and we want to find it in it says there is the text is inside. This is a line of text, it should return true. And then we can search for other pieces of text that say we search for our if there is our insight, this is a line of text, it should return true else it should return false. This operation is important to be used inside loops and conditional statements. So this is the end of section one and in the next coming sections. I'm going to consider other problems related to text