Slide 1

Slide 1 text

INTRO TO PYTHON

Slide 2

Slide 2 text

Hi

Slide 3

Slide 3 text

Eleni Lixourioti aka @geekfish_

Slide 4

Slide 4 text

I ❤ python ! ! " #

Slide 5

Slide 5 text

PYTHON

Slide 6

Slide 6 text

Programming language

Slide 7

Slide 7 text

Hi

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

1991

Slide 10

Slide 10 text

Guido Van Rossum

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

B.D.F.L.

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

GENERAL-PURPOSE

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

▸ Marketing/Advertising ▸ Telecommunications ▸ Commerce ▸ Governance ▸ Graphics ▸ CGI ▸ Finance ▸ Medicine ▸ Engineering ▸ Home automation ▸ …

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Slide 19

Slide 19 text

DATA SCIENCE / MACHINE LEARNING

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

DevOps

Slide 22

Slide 22 text

Education

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Games development

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

SURVEY

Slide 28

Slide 28 text

WHY BOTHER?

Slide 29

Slide 29 text

Windows Mac Linux Mobile (somewhat)

Slide 30

Slide 30 text

You can start small

Slide 31

Slide 31 text

and grow REALLY BIG

Slide 32

Slide 32 text

The most important thing: ?

Slide 33

Slide 33 text

The most important thing: Python Philosophy

Slide 34

Slide 34 text

import this

Slide 35

Slide 35 text

ZEN OF PYTHON

Slide 36

Slide 36 text

> 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}")

Slide 54

Slide 54 text

Numbers

Slide 55

Slide 55 text

a = 10 b = 5 a + b a - b a * b a / b

Slide 56

Slide 56 text

Comparisons

Slide 57

Slide 57 text

10 == 5 10 == 10 10 > 5 10 < 5 10 != 5 10 >= 5

Slide 58

Slide 58 text

"potato" == "tomato" "tomato" == "tomato" "TOMATO" == "tomato"

Slide 59

Slide 59 text

"Bob" > "Alice"

Slide 60

Slide 60 text

!

Slide 61

Slide 61 text

"Xena" > "Hercules"

Slide 62

Slide 62 text

!

Slide 63

Slide 63 text

Now with variables!

Slide 64

Slide 64 text

a = 10 b = 5 a == b a > b

Slide 65

Slide 65 text

Conditionals

Slide 66

Slide 66 text

if / else

Slide 67

Slide 67 text

animal = "cobra" if animal == "python": print("Are you related to Python?") else: print("nevermind...")

Slide 68

Slide 68 text

Why don't we use {brackets} ?

Slide 69

Slide 69 text

Indentation

Slide 70

Slide 70 text

"There should be one-- and preferably only one --obvious way to do it" ~ Zen of Python

Slide 71

Slide 71 text

4 spaces

Slide 72

Slide 72 text

....block_a ........block_b ........still_block_b ........more_block_b ............block_c ....back_to_block_a

Slide 73

Slide 73 text

if / elif / else

Slide 74

Slide 74 text

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}")

Slide 90

Slide 90 text

def print_business_card(name, occupation): print(f"{name}: professional {occupation}") print_business_card("Linda", "Python-Whisperer") print_business_card("Alice", "Potato Chip Inspector")

Slide 91

Slide 91 text

RETURN

Slide 92

Slide 92 text

def get_business_card(name, occupation): return f"{name}: professional {occupation}" linda_card = get_business_card("Linda", "Python-Whisperer") alice_card = get_business_card("Alice", "Potato Chip Inspector") print(f"Here are my associates: {linda_card} and {alice_card}")

Slide 93

Slide 93 text

Did you return??? — Post it note from my boss myself

Slide 94

Slide 94 text

Built-in functions

Slide 95

Slide 95 text

print("giraffe") # giraffe len("giraffe") # 7 min(4, 10, 2, 9) # 2 max(4, 10, 2, 9) # 10 int("100") 100 str(100) "100"

Slide 96

Slide 96 text

Object Functions

Slide 97

Slide 97 text

"hello".upper()

Slide 98

Slide 98 text

ADVENTURE TIME (TAKE 2)

Slide 99

Slide 99 text

https://repl.it/@Geekfish/RoadTrip2

Slide 100

Slide 100 text

Optional

Slide 101

Slide 101 text

Lists & Loops

Slide 102

Slide 102 text

rainbow_colours = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'] for colour in rainbow_colours: print(colour)

Slide 103

Slide 103 text

Dictionaries

Slide 104

Slide 104 text

human = { "name": "Louise", "favourite_colour": "green", } human["name"] # Louise human["favourite_colour"] # green

Slide 105

Slide 105 text

Built-in modules

Slide 106

Slide 106 text

import this

Slide 107

Slide 107 text

import random random.choice(['work', 'study', 'play', 'sleep']) # sleep, hopefully? # --- or --- from random import choice choice(['work', 'study', 'play', 'sleep'])

Slide 108

Slide 108 text

from datetime import datetime print(datetime.now())

Slide 109

Slide 109 text

TUTORIALS/RESOURCES ▸ Python 3 Documentation ▸ PEP8 (Python styling guide) ▸ Learn Python the Hard Way ▸ DjangoGirls Django Tutorial

Slide 110

Slide 110 text

HUMANS ▸ WTH Slack (#code_talk) ▸ CodeHub Bristol ▸ Python DBBUG

Slide 111

Slide 111 text

BEGINNER-FRIENDLY CONFERENCES ▸ PyCon UK (Cardiff, September) ▸ EuroPython (Edinburgh, July) ▸ DjangoCon Europe (Heidelberg Germany, May)

Slide 112

Slide 112 text

Thank you ❤ Questions / Support ? [email protected] @geekfish_