Data type: string¶
Objectives¶
Every programming language is using strings as a data type. The Python way to handle strings, is shown in this station. |
Instructions¶
Tasks: |
---|
- Save the following text, line by line into variables:
"Shall I compare thee to a summer's day?
Thou art more lovely and more temperate..."
Lines from Shakespeare's Sonnet 18.
- Return the values of all variables with the print-Function. Don’t forget the empty line.
Properties and rules¶
- A string is enclosed in the following characters: single quotation, double quotation and triples of the quotation signs.
- Strings are immutable, if you change a string, the computer has to reserve new memory and afterward release the old memory.
- Each character is callable with an index. The index counting starts at zero.
More hints about strings kann be found at:
Assign strings¶
Each variable get’s own value.
todo: find a good equivalent to the german version...
Concatenate strings¶
Building longer Strings from substrings, is an often used technique.
Hint: | The same result can be achieved with other data types tuple and list. |
---|