Strings

Fill in the blanks

In Python, are a sequence of characters enclosed within either single ('') or double ("") quotation marks. They can be manipulated in various ways using different operations and functions. One fundamental operation is , which allows us to combine two or more strings together using the '+' operator. For example, "Hello" + " " + "World!" will result in the string "Hello World!".

To access individual characters within a string, we can use ing. Each character in a string has an index starting from 0. Thus, the first character can be accessed using string_name[0], the second character with string_name[1], and so on. Similarly, we can obtain a portion of a string, known as a , by specifying a range of indices using the slicing notation. For instance, string_name[2:5] will extract the characters at indices 2, 3, and 4.

To determine the of a string, the len() function can be used. It returns the number of characters present in the string, including spaces and special characters. Moreover, strings are , meaning once a string is created, it cannot be modified. Any operation that appears to modify a string actually creates a new string.

When strings, it is important to consider their . For instance, "Hello" and "hello" are not considered equivalent. To perform case-insensitive comparisons, we can convert both strings to either lowercase or uppercase using the lower() or upper() methods, respectively, before comparing them.

are built-in functions specifically designed for string manipulation. They provide numerous functionalities such as finding substrings within a string, replacing characters, converting cases, removing leading/trailing spaces, and more. s are also crucial in strings, as they allow the representation of special characters such as newline (\n), tab (\t), or backslash (\\).

Keywords

index | substring | concatenation | length | strings | escape sequence | case sensitivity | comparing | string methods | immutable |