Professional Documents
Culture Documents
Data types: Defines operators functions/methods. What we can do with data type.
Name str
customer ID int (if there is characters, we
can use str)
Postcode int
Do you own or rent string/bool (encode, own =
true, rent = false)
length of bench top float
width of bench top float
are you interested in further bool
offers
“7cakes”
357.23
True
bool(“”) = False
bool(“ “) = True
Operators
+,-, *, /, //, %, **
1+2
+ is an operator.
1+12
3a a/a 1.0
3b b+b 4
3c b+c 4.0
3d a/b 0.5
3e a //b 0
3f a%b 1
3g a+b/c 2.0
3h 1.5
1%2=1
2%2=0
3%2=1
1%3=1
2%3=2
13 % 4 = 1
4a. 246
4b. 123123
4c. Error
4d. 12
4e. ‘3333’
4f. Error
Tutorial sheet 4
Discussion
1. Boolean is a true or false condition. It stores ‘true’ or ‘false’. Other types can be
converted to it. Empty strings “” is false; zero is also false.
2. (a) Boolean value; (b) a relational operator; (c) a logical operator
4. Sequence?
5. Index: variable_name[num]
6. Slice: variable_name[start:end:direction,step]
7. Function:
What is a function?
Function takes a set of input values, perform some calculation based on them, and return a
value.
reutrn is optional
Exercise
>> False
2. Give an example of a value for ‘var’ which trigger it and one which not
3. Mistake
4. Mistake
assignment is =
5. Evaluate: s = “python”
p y t h o n
0 1 2 3 4 5
-6 -5 -4 -3 -2 -1
a s[1] y
b s[-1] n
d s[10] Error
f s[-4:-2] th
g s[:-4] py
i s[::-1] nohtyp
In order to use the output of a function (to assign it to a variable) we need to return a value.
IDE:
Sublime
Grok
PyCharm
Python IDE
Jupyter notebook