官术网_书友最值得收藏!

String concatenation and replication

+ is the concatenation operator that's used in Python to concatenate two strings. As always, the result of the concatenation is a new string and unless we get the updated string, the update will not be reflected with the original string object. The + operator is internally overloaded to perform concatenation of objects when it is used on string types. It is also used for the addition of two numbers when used on numeric data types, like so:

Interestingly, Python also supports another operator that gets overloaded when used with string data types. Instead of performing a conventional operation, this operator performs a variation of the original operation so that the functionality can be replicated across string data types. Here, we are talking about the multiplication operator, *. This is conventionally supposed to perform the multiplication of numeric data types, but when it is used on string data types, it performs a replication operation instead. This is shown in the following code snippet:

In the preceding case, the multiplication operator actually replicates the Hello world string stored in the c variable five times, as we specified in the expression. This is a very handy operation and can be used to generate fuzzing payloads, which we will see in the later chapters of this book.

主站蜘蛛池模板: 申扎县| 通渭县| 宣汉县| 荃湾区| 巩留县| 鄂托克旗| 绥滨县| 莆田市| 广州市| 邵阳县| 镇平县| 根河市| 鲜城| 绥滨县| 班玛县| 望城县| 松溪县| 疏附县| 石河子市| 宜阳县| 永善县| 鄂伦春自治旗| 鱼台县| 珲春市| 吴旗县| 滁州市| 塔城市| 上杭县| 武鸣县| 美姑县| 海伦市| 尚志市| 盐城市| 云梦县| 容城县| 棋牌| 五台县| 成武县| 揭阳市| 壤塘县| 江口县|