> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Slide 37
Slide 37 text
Beautiful is better than ugly
Slide 38
Slide 38 text
Simple is better than complex
Slide 39
Slide 39 text
...
Slide 40
Slide 40 text
Readability counts
Readability counts
Slide 41
Slide 41 text
Computer
Humans
Slide 42
Slide 42 text
Keep it simple
Slide 43
Slide 43 text
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello Java!");
}
}
Slide 44
Slide 44 text
print("Hello Python!")
Slide 45
Slide 45 text
Be expressive
Slide 46
Slide 46 text
rainbow_colours = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
for colour in rainbow_colours:
print(colour)
Slide 47
Slide 47 text
https://repl.it/@Geekfish/python
Slide 48
Slide 48 text
print("Hello Python!")
42 + 9
5 * 6
Slide 49
Slide 49 text
Variables
Slide 50
Slide 50 text
name = "Linda"
Slide 51
Slide 51 text
name = "Linda"
print("Hello " + name)
Slide 52
Slide 52 text
Strings
Slide 53
Slide 53 text
name = "Linda"
occupation = "Python-Whisperer"
print(f"{name}: professional {occupation}")
age = 30
if age < 8:
print("Sorry, you are not allowed into the Haunted house!")
elif age < 12:
print("Sorry, you are not allowed to ride the roller coaster")
else:
print("Being a grown-up is great!")
Slide 75
Slide 75 text
?!? Errors ? &*!@£ !
Slide 76
Slide 76 text
animal = "turtle"
print(f"I love my pet {aminal}")
# NameError: name 'aminal' is not defined
Slide 77
Slide 77 text
"Xena" > 9000
# TypeError: '>' not supported between instances of 'str' and 'int'
Slide 78
Slide 78 text
Things will break a lot ! "
Slide 79
Slide 79 text
Deep breath, patience, read carefully
Slide 80
Slide 80 text
But if that fails Google may help too !
Slide 81
Slide 81 text
Comments
Slide 82
Slide 82 text
# this line is completely ignored!
print("Hello!)
# print("Hi!")
print("How rude...")
Slide 83
Slide 83 text
ADVENTURE TIME
Slide 84
Slide 84 text
https://repl.it/@Geekfish/RoadTrip
Slide 85
Slide 85 text
Multiple conditions
Slide 86
Slide 86 text
if sky == "blue":
if temperature > 20:
print("Let's go swimming!")
# Same as:
if sky == "blue" and temperature > 20:
print("Let's go swimming!")
Slide 87
Slide 87 text
10 == 10 and 20 < 21
5 > 10 or 100 > 99
Slide 88
Slide 88 text
Functions
Slide 89
Slide 89 text
name = "Linda"
occupation = "Python-Whisperer"
print(f"{name}: professional {occupation}")