How to use strings ( slicing, concatenate ,formatting) in python syntax | for beginners

#python #strings #pythonsyntax Creating a String To create a string in Python, you can simply enclose a sequence of characters in quotes. For example: ```python my_string = “Hello, World!” ``` You can also use single quotes to create a string: ``python my_string = ‘Hello, World!’ ``` Both single and double quotes can be used interchangeably, as long as they are used consistently within the same string. Accessing Characters in a String You can access individual characters in a string by using indexing. In Python, indexing starts from 0, so the first character of a string is at index 0, the second character is at index 1, and so on. For example: ```python my_string = “Hello, World!” print(my_string[0]) # Output: H print(my_string[7]) # Output: W ``` You can also use negative indexing to access characters from the end of the string. For example, `-1` represents the last character, `-2` represents the second last character, and so on.
Back to Top