Posts

Showing posts with the label Working with Strings

Python - Working with Strings

Image
A string is a sequence of Unicode characters. We can use single or double quotes to create a string. str1 = 'Python' str2 = "Hello" print(str1) # Python print(str2) # Hello If you have a long line, you can divide it into sections and paste them on different rows of code. Here, the whole line is enclosed in parentheses, and each section is in quotes: text = ( "Learn python programming "         "language " ) print(text) # Learn python programming language Multiline strings can be denoted by triple quotes, ''' or """: ''' This is a comment ''' text1 = '''A string is a sequence of Unicode characters. We can use single or double quotes to create a string. ''' print(text1) # or text2 = """A string is a sequence of Unicode characters. We can use single or double quotes to create a string. """ print(text2) Escape sequences in a string The string can al