Introduction to python

37
Introduction to Python Introduction to Python Yi-Fan Chu, 2016 Social Network Application Department of Computer Science, University of Taipei

Transcript of Introduction to python

Introduction to Python

Introduction to PythonYi-Fan Chu, 2016

Social Network ApplicationDepartment of Computer Science, University of Taipei

Introduction to Python

Overviews1.Introduction

2.Syntax

3.List and Dictionary

4.For loop

5.Implementation

Introduction to Python

Beautiful, Simple, Explicit…

Rapid development

Item by item

Introduction

Introduction to Python

Overviews1.Introduction

2.Syntax

3.List and Dictionary

4.For loop

5.Implementation

Introduction to Python

Semicolon is not needed.

Data type declaration is not needed.

Indented with logic

Syntax

3.Indented with logic

1.Semicolon is not needed

2. Data type declaration is not needed.

Introduction to Python

Indented with logic

Different indentation with different result.

Introduction to Python

Overviews1.Introduction

2.Syntax

3.List and Dictionary

4.For loop

5.Implementation

Introduction to Python

Data Structure to save data, just like “array”

With different index

List and Dictionary

Introduction to Python

Array

Different data type items in the same list

List

Introduction to Python

[ ]

[1,2,3,4,5]

[ “abc”, ”def”, ”ghi”]

[1, ”abc”, 1.253, [1,2,3], {“xyz”:”hahaha”} ]

List

int string float list dictionary

Introduction to Python

Key-Value

Key : int, float, string

Value : int, float, string, list, dictionary

Dictionary

Introduction to Python

{ Key : Value }

{ Key : Value, Key : Value, Key : Value…}

Dictionary

Introduction to Python

{ Key : Value }

{ “name” : “Apple”,

“color” : “red”,

“amonut” : 3 }

Dictionary

Key Value

Introduction to Python

List and Dictionary

[ “apple”, “red”, “3” ]

{ “fruit”:“apple”, “color”:“red”, “amount”:“3” }

Key : 0 1 2

Value: apple red 3

Key : fruit color amount

Value: apple red 3

Introduction to Python

Overviews1.Introduction

2.Syntax

3.List and Dictionary

4.For loop

5.Implementation

Introduction to Python

Item by item

Without entering condition

For loop

Introduction to Python

for( int i; i < 10; i++){

blah blah blah; }

For loop

for item in list/dictionary:

item = item + 1

C / Java

Python

With Condition

Without Condition

Introduction to Python

Overviews1.Introduction

2.Syntax

3.List and Dictionary

4.For loop

5.Implementation

Introduction to Python

Implementation

Checkpoint1 : For loop

Checkpoint2 : List of Dictionary

Introduction to Python

ImplementationSetup environment

Making lists of number and strings

Try to use for loop

Making a directory of fruit

print something from directory

Introduction to PythonSet your env like thisIf you’d like to edit by vim, just go ahead!

Introduction to PythonCreate a new file.Sublime Text 2 / File / New File

Introduction to PythonSave the file on Desktop.Sublime Text 2 / File / Save

Introduction to PythonMake two lists.A list for int, a list for strings.

Introduction to PythonTry the for loop.For every number in list a…

Introduction to PythonGo to Desktop and execute.What do you think the result is?

Introduction to PythonResultIs the result same as you think?

Introduction to PythonMake a dictionary of fruit.

Introduction to PythonExecute again.What do you think the result is?

Introduction to PythonExecute again.Is the result same as you think?

Introduction to Python

Implementation

Checkpoint1 : For loop

Checkpoint2 : List of Dictionary

Introduction to PythonMake a list of dictionary.

Introduction to PythonPut some data in them.

Introduction to PythonLet’s try some “if”,“else”

Introduction to PythonExecute again

Introduction to PythonResultIs the result same as you think?