Chapter 1
Interactive shell -> REPL: read-evaluate-print loop -> lets you run (execute) python instructions
one at the time and instantly shows you the results.
Entering expressions in to the interactive shell
Launching the Mu editor, download when going through the set up in the preface.
MacOS open your applications folder and double click Mu
, 2
Click the new button and save an empty file as blank.py
When you run this blank file by clicking the run button, it will open the interactive shell which will
open as new pane that opens at the bottom of the Mu editor window.
The integer, floating-point, and string data types
Stings -> strs => need to put ‘ ‘ around a string
Error message: syntaxError: EOL while scanning string literal => probably forgot the final single
quote character at the end of a string.
String concatenation and replication
+ It joins the stings as the string concatenation operator
>>> ‘alice’+’bob’
‘Alicebob’
>>> ‘alice’ + 42
Can't use a string in combination with a integer value => TypeError: can only concatenate str
(not “int” to str
The * operator multiples two integer or floating-point values, but when * is used on one string
value and one integer value it becomes the string replication operator.
>>> ‘alice’ * 5
‘Alicealicealicealicealice’
, 3
Storing values in variables
A variable is initialized or created the first time a value is stored in it. After that you can use it in
expression with other variables and values. When a variable is assigned a new value the old
value is forgotten. This is called overwriting the variable.
A good variable name describes the data it contains. There are three rules:
- It can be only one word with no spaces
- It can use only letters, numbers and the underscore (_) character
- It can't begin with a number
Variable names are case-sensitive. Consistency with the style guide is important.
Chapter 2
Flow control statements can decide which python instructions to execute under which
conditions. These flow control statements directly correspond to the symbols in a flow chart.
-> flow chart is een goede representation of hoe programeren werkt
Boolean values
Boolean data type has two values: True and False -> always with capital F or T
Like any other value, boolean values are used in expressions and can be stored in variables. If
you don't use the proper case or you use true and false for variable names python will give an
error.
Comparison operators
Comparison operators, also called relational operators, compare two values and evaluate down
to a single boolean value.
An integer or floating-point value will always be unequal to a string value.
The <,>,<= and >= operators work properly only with integer and floating point values.
Boolean operators
Three boolean operators (and, or, and not) are used to compare boolean values. Like
comparison operators, they evaluate these expressions down to boolean values.
, 4
- Binary boolean operators: the ‘and’ and ‘or’ operators always take two boolean values
(or expressions) so they are considered binary operators.
The and operator evaluate an expression to true if both boolean values are true otherwise it
evaluates to false.
The or operator evaluates an expression to true if either of the two boolean values is true. If
both are false it evaluates to false.
- Unary operator -> The not operator
Unlike and/or the not operator operates only on e boolean value (or expression). This makes it a
unary operator. The not operator simply evaluates the opposite boolean value.
>>> not True
False
>>> not not not not Ture
True
Voordelen van het kopen van samenvattingen bij Stuvia op een rij:
Verzekerd van kwaliteit door reviews
Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!
Snel en makkelijk kopen
Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.
Focus op de essentie
Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!
Veelgestelde vragen
Wat krijg ik als ik dit document koop?
Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.
Tevredenheidsgarantie: hoe werkt dat?
Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.
Van wie koop ik deze samenvatting?
Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper brittvandewouw23. Stuvia faciliteert de betaling aan de verkoper.
Zit ik meteen vast aan een abonnement?
Nee, je koopt alleen deze samenvatting voor €6,56. Je zit daarna nergens aan vast.