Python String Concatenation | Python Find String in List
In this lecture, we will discuss â€œPython String Concatenation | Python Find String in Listâ€. If you are a new visitor to my website, you can also read my previous lecture that is written about string in details. Are you know about string? ooh, that’s not a problem.
First, we are going to learn about string in python. Then we will discuss how to concatenate with other data types. Also, You can learn how to print a specific word in a given string.[mks_pullquote align=”left” width=”848″ size=”15″ bg_color=”#ecf7b9″ txt_color=”#282828″]
A string value is written in double quotation (” “). Single quotes work will be the sameÂ as double quotesÂ in Python.
Â name = "ABDUL JABBAR"[/mks_pullquote]
Python String Concatenation
Python String Concatenation Int to String
name = ("my name is "+2) print (name) Output: Â Error will occur. Because string cannot be concatenated with Int Data Types.[mks_pullquote align=”left” width=”848″ size=”16″ bg_color=”#ddb8b8″ txt_color=”#161616″]Note: There is may the following error occurs “string cannot be concatenated with Int Data Types”. You need to convert int to str to concatenate and get the required output. As you see in the following program that is given below.[/mks_pullquote]
name = ("my name is "+ "2") print (name) Output: Â my name is 2.
The correct answer, because the string can be concatenated with other string because Data typesÂ are same of both values.
Concatenate int to string with multiplication Sign
Example:4 name = ("my name is"*2) print (name) Output: my name is my name is
When we multiply any string with an integer that string’s alphabets will be repeated. You can see above the programâ€™s Output â€œmy name isâ€ string repeated 2 times.
Python Find String in List
Print any specific word or alphabets in a given string?
It is much important and useful and widely used in a programming concept. Google also used this concept.
str = "abcabcabcabcabc" Â Â # if we want to print â€˜bâ€™ that is at a second position in the given string. print (str) Output: b
str = "friend"Â Â Â Â Â Â #we will access â€œiâ€ keyword from the following statements print (str)Â Â Â Â Â Â Â # e keyword at fourth position we can acess through 3 because index start from 0. Output: Â e
Because the index of the string will start from 0. And â€œbâ€ in the second position in the given string then we can write the following above statements to access this specific alphabet.
str = "friend"Â Â Â print (str)Â Â Â Â # because 8 is out of range, does not exist in any alphabet. Output: Â string index out of range
In the last example, you can see the string index is out of range. Because any alphabet does not exist at a given index in the above example. Indexing starts from 0. when the index of the string does not exist then your answer will be out of range.
[mks_pullquote align=”left” width=”848″ size=”15″ bg_color=”#dda44d” txt_color=”#0a0a0a”]I hope this article is very helpful to understand â€œPython String Concatenation | Python Find String in Listâ€. If you have any question then you can discuss in the comments section. Please also give your feedback. You can also learn HTML5, PHP7, Bootstrap4.0 and many other programming languages. Thank you!.[/mks_pullquote]