GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Python String - GeeksforGeeks Python StringLast Updated : 19 Sep, 2026 Strings are sequence of characters written inside quotes. It can include letters, numbers, symbols and spaces. Python does not have a separate character type.
Creating a StringStrings can be created using either single ('...') or double ("...") quotes. Both behave the same.
Output GFG GeeksForGeeks Multi-line StringsUse triple quotes ('''...''' ) or ( """...""") for strings that span multiple lines. Newlines are preserved.
Output I am Learning Python String on GeeksforGeeks I'm a Geek Accessing Characters in StringStrings are indexed sequences. Positive indices start at 0 from the left, negative indices start at -1 from the right as represented in below image: ![]() Example 1: Access specific characters through positive indexing.
Output A E
Example 2: Read characters from the end using negative indices.
Output D B String SlicingSlicing is a way to extract a portion of a string by specifying the start and end indexes. The syntax for slicing is string[start:end], where start starting index and end is stopping index (excluded).
Output BCD ABC DEF FEDCBA Looping Through StringsStrings are iterable, which means we can access each character one by one using a loop.
Output A B C D E F Explanation: for loop goes through the string in order and each iteration prints the next character. String ImmutabilityStrings are immutable, meaning their values cannot be changed after creation. Any modification to a string creates a new string instead of altering the original one.
Output ABCDEF Explanation: original string "aBCDEF" is not modified. A new string is created by combining "A" with s[1:] (rest of the string). Deleting a StringIndividual characters of a string cannot be deleted because strings are immutable. However, an entire string variable can be removed using del keyword.
Updating a StringStrings cannot be changed directly after creation. So any modification results in a new string being created using slicing or methods like replace().
Output HBCD EF abcD EF Explanation:
Common String MethodsPython provides various built-in methods to manipulate strings. Below are some of the most useful methods: 1. len(): returns the total number of characters in a string (including spaces and punctuation).
Output 13 2. upper() and lower(): upper() method converts all characters to uppercase whereas, lower() method converts all characters to lowercase.
Output HELLO WORLD hello world 3. strip() and replace(): strip() removes leading and trailing whitespace from the string and replace() replaces all occurrences of a specified substring with another.
Output ABC Python is awesome
Concatenating and Repeating Strings1. Concatenation: Strings can be combined by using + operator.
Output Hello World 2. Repetition: A string can be repeated multiple times using *.
Output Hello Hello Hello Formatting Strings1. Using f-strings: f-strings allows to directly insert variables and expressions inside a string using {} brackets.
Output Name: Jake, Age: 22 2. Using format(): format() method allows inserting values into placeholders {} inside a string.
Output My name is Emily and I am 22 years old. String Membership Testingin keyword is used to check whether a substring exists inside a string. It returns True if the substring is found, otherwise it returns False.
Output True False Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |