What is a String?
A string it is a sequence of characters, which can contain both numbers and letters. But, let's highlight, that this sequence of characters must be enclosed in quotation marks (either single or double).
Example of creating a string using single quotes:
pythonInput:string = 'Python'print('One of the most popular programming language is:', string)Output:One of the most popular programming language is: Python
Example of creating a string using double quotes:
pythonInput:string = "Python"print('One of the most popular programming language is:', string)Output:One of the most popular programming language is: Python
It is important to know how to create multi-line strings. In these situations single and double quotes do not work. Here we need to use three quotes. Let's look at what this looks like in practice.
pythonInput:string = '''Roses are redViolets are blueCats can learn PythonWhat about you?'''print(string)Output:Roses are redViolets are blueCats can learn PythonWhat about you?
Python 3.6 has a way to format strings that allows us to use built-in expressions inside string constants. This approach is called f-strings
Let's look at the examples.
pythonInput:string = 'world'print(f'Hello, {string}')Output:Hello, world
pythonInput:a = 5b = 13print(f'{a} + {b} = {a+b}')Output:5 + 13 = 18
Swipe to start coding
You have to fill in the blanks.
Solução
Obrigado pelo seu feedback!