Python Strings Explained for Beginners (With Simple Examples)
Python Strings Explained for Beginners (With Simple Examples) Python Strings Explained for Beginners (With Simple Examples) Introduction After learning Nested Loops, now we move to one of the most commonly used topics in Python — Strings . Strings are used to store and work with text data . --- What is a String? A string is a sequence of characters enclosed in quotes. name = "Ayush" message = 'Hello World' Strings can be written using single quotes (' ') or double quotes (" "). --- Accessing Characters (Indexing) text = "Python" print(text[0]) # P print(text[3]) # h Index always starts from 0 . --- String Slicing text = "Python" print(text[0:4]) # Pyth print(text[2:]) # thon Slicing allows you to extract part of a string. --- String Length text = "Python" print(len(text)) --- Common String Methods 1. Convert to Uppercase text = "python" ...