Hello Python!
Maryam Tavakol
Machine Learning Group
1
Winter semester 2016/17
Hello Python! Maryam Tavakol Machine Learning Group Winter - - PowerPoint PPT Presentation
Hello Python! Maryam Tavakol Machine Learning Group Winter semester 2016/17 1 Programs & Programming A program is a set of instructions Every program is written in terms of a few basic operations that its reader already understands
Maryam Tavakol
Machine Learning Group
1
Winter semester 2016/17
useful things is the heart and soul of programming
2
3
4
*http://www.c4learn.com/c-programming/compiler-vs-interpreter/
saved in a file
by Python interpreter
possible in a program called a shell
>>> 4+13 17
binary operators
6
>>> 212 - 32 * 5 / 9 194.2223 >>> (212 - 32) * 5 / 9 100.0
7
8
>>> 2 == 2 #Equality True >>> 2 != 2 #Inequality False >>> 0 < 2 < 5 #Chained inequality True >>> 2 > 2 False
9
Comments!
>>> not 1 == 1 False
>>> 2 == 2 and 1 != 1 True
is evaluated and the resulting value is returned
>>> 2 == 2 or 1 != 1 False
10
11
12
>>> degree_celsius = 26.0 >>> 9 /5 * degree_celsius + 32 78.8 >>> difference = 100 - degree_celsius >>> diference 74
13
14
>>> degree_celsius = 26.6
value 26.0
15
«variable» = «expression»
(with a memory address)
reuse the existing variable)
16
Consider this code:
>>> difference = 20 >>> double = 2 * difference >>> double 40 >>> difference = 5 >>> double 40
18
>>> score = 50 >>> score 50 >>> score = score + 20 >>> score 70 >>> score = 50 >>> score 50 >>> score += 20 >>> score 70
19
>>> 3 + moogah Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'moogah' is not defined >>> 3 + ^ SyntaxError: invalid syntax
20
parentheses
backslash, \
21
22