Python for beginners: Difference between revisions
From Algolit
Line 1: | Line 1: | ||
== Literary Python for Beginners == | == Literary Python for Beginners == | ||
− | + | Next pages: [[Python_for_beginners/loops_and_conditions|Loops and Conditions]] // [[Python_for_beginners/anthology|Create anthology]] | |
− | + | === VARIABLES === | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === | ||
* Introduction to the objects string & list with their different attributes | * Introduction to the objects string & list with their different attributes | ||
− | * uses the shell or | + | * uses the shell or editor |
Line 26: | Line 15: | ||
A string is defined by " " | A string is defined by " " | ||
− | '''* | + | '''* Write text using STRING''' |
+ | |||
+ | >>> print("La Cambre") | ||
− | + | ** Exercise: Write your name''' | |
− | + | >>> ... | |
− | + | '''* Adding text''' | |
− | + | >>> print("Brussels"+"Paris") | |
− | >>> " | + | >>> print("Brussels "+"Paris") |
− | |||
− | + | ** Exercise: Write your address''' | |
− | + | '''* Composing a sentence''' | |
− | >>> " | + | >>> print("Paris", "to", "London", "via", "Brussels") |
− | >>> | + | >>> print("Paris to London via Brussels") |
− | + | ** Exercise: Write your favourite expression''' | |
− | + | '''* Multiply''' | |
+ | >>> print(3*3) | ||
− | ** Exercise: Write 'I write the alphabet 3 times. | + | >>> 3 * "algolit" + " in Brussels" |
+ | |||
+ | ** Exercise: Write 'I write the alphabet' 3 times. | ||
Note: there are always different possible solutions | Note: there are always different possible solutions | ||
Line 65: | Line 58: | ||
>>> letter = "a" | >>> letter = "a" | ||
− | >>> print letter | + | >>> print(letter) |
>>> word = "algolit" | >>> word = "algolit" | ||
− | >>> print word | + | >>> print(word) |
− | >>> sentence = "I learn to read and write again | + | >>> sentence = "I learn to read and write again in Python." |
− | >>> print sentence, letter | + | >>> print(sentence, letter) |
** Exercise: print your letter, word, sentence | ** Exercise: print your letter, word, sentence | ||
Line 80: | Line 73: | ||
'''* add punctuation''' | '''* add punctuation''' | ||
− | >>> print letter + " " + word + " " + sentence + "." | + | >>> print(letter + " " + word + " " + sentence + ".") |
− | >>> print letter + "! " + word + "? " + sentence + "." | + | >>> print(letter + "! " + word + "? " + sentence + ".") |
>>> letter = "i" | >>> letter = "i" | ||
Line 91: | Line 84: | ||
− | ''' | + | '''What you've learned''' |
− | + | ||
− | + | * variable | |
− | + | * value | |
− | + | * assignment operator (=) | |
− | + | * difference between variables and values | |
− | + | * integers | |
− | + | * print() | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | * | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Revision as of 14:21, 21 November 2020
Literary Python for Beginners
Next pages: Loops and Conditions // Create anthology
VARIABLES
- Introduction to the objects string & list with their different attributes
- uses the shell or editor
# USING STRINGS
A string is a chain of characters / text and can contain any type of characters
A string is defined by " "
* Write text using STRING
>>> print("La Cambre")
- Exercise: Write your name
>>> ...
* Adding text
>>> print("Brussels"+"Paris")
>>> print("Brussels "+"Paris")
- Exercise: Write your address
* Composing a sentence
>>> print("Paris", "to", "London", "via", "Brussels")
>>> print("Paris to London via Brussels")
- Exercise: Write your favourite expression
* Multiply
>>> print(3*3)
>>> 3 * "algolit" + " in Brussels"
- Exercise: Write 'I write the alphabet' 3 times.
Note: there are always different possible solutions
* write string as variable
- Avoids having to retype your string each time you use it
- You can change values at any time of the writing process
>>> letter = "a"
>>> print(letter)
>>> word = "algolit"
>>> print(word)
>>> sentence = "I learn to read and write again in Python."
>>> print(sentence, letter)
- Exercise: print your letter, word, sentence
* add punctuation
>>> print(letter + " " + word + " " + sentence + ".")
>>> print(letter + "! " + word + "? " + sentence + ".")
>>> letter = "i"
>>> print letter + "! " + word + "? " + sentence + "."
- Exercise: change content of one of variables, over and over, see how result changes
What you've learned
- variable
- value
- assignment operator (=)
- difference between variables and values
- integers
- print()