Legacy - String Concatenation and Replication Workout
- 03:08
Learn how to concatenate and replicate string in PyCharm.
Transcript
Let us now look at string concatenation and replication in PyCharm, we can use the code editor or the Python console to perform these operations. But purely due to the simplicity of the operations, we shall use the Python console in PyCharm. In order to access the Python console in PyCharm, we need to go to Tools and select Python console. So firstly, in order to concatenate reuse the plus side at Python, so to concatenate two strings, say, current assets. And if we press enter, we get current assets. So we can concatenate two strings, we can observe that there wasn't any space between current and assets in order to get a space between current assets. We can either have a space here or in front of the assets to get the space current assets. Well, in order to concatenate two integers together, we again use the plus sign, which is possible. But the question is, can we concatenate an integer with a string the answer is no as we could either concatenate a string with a string or an integer with an integer? The next question is, can we concatenate floating point numbers? The answer is, yes. So if we want to concatenate a floating point number 4.5 into 6.5. That is possible. Again, for concatenation, we use the plus sign, can we concatenate floats with an integer? Yes, we can. But we cannot concatenate a float with a string. So imagine you've got a two which is an integer you want concatenated with a 4.5, which is a float that is possible, as Python considers the two as a 2.0. Now, for replicating, we cannot replicate a string with a string. As we can see, if we want to replicate a current with the asset, it's going to return an error. And for replication in Python, we use the star side, it is possible to replicate a string with an integer. For example, if we go to string as tangible assets, and if we try to replicate this with an integer of three, it's going to return three tangible assets. We cannot replicate a string with a floating point number. So if we try to replicate a tangible asset string with a floating point number of 3.0, it's going to return an error. Because imagine rather than a 3.0. If we have a 3.5, it is not going to return three tangible assets with a half of tangible asset. That doesn't make sense. In the case of replication, we can replicate screens with an integer. But in case of a concatenation, we can concatenate same data type items in Python.