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

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.

主站蜘蛛池模板: 疏勒县| 桦南县| 湘潭市| 墨竹工卡县| 铁岭市| 冀州市| 比如县| 临澧县| 全椒县| 武川县| 太仆寺旗| 孟连| 阳东县| 锡林浩特市| 门头沟区| 西平县| 安庆市| 凤山市| 临清市| 江川县| 嵊泗县| 同德县| 阜宁县| 宜章县| 神农架林区| 庆元县| 九寨沟县| 内乡县| 城固县| 杂多县| 华蓥市| 福安市| 宣城市| 顺昌县| 平乡县| 大安市| 海林市| 涞水县| 伊宁县| 三穗县| 临桂县|