Python
郭⾄至軒(KuoE0)
KuoE0.tw@gmail.com
KuoE0.ch

@ Programming Language 2013
Attribution-ShareAlike 3.0 Unported
(CC BY-SA 3.0)
http://creativecommons.org/licenses/by-sa/3.0/
Latest update: Jan 10, 2...
What is Python?
What is Python?

a programming language
What is Python?
easy to Read
easy to Write
easy to Learn
a programming language
Top Language in TIOBE
Position
May 2013

Position
May 2012

Delta in
Position

Programming Language

1
2
3
4
5
6
7
8
9
10
...
Top Languages in Github
Javascript

21%

Ruby

12%

Java

8%

Python

8%

Shell

8%

PHP

7%

C

6%

C++

5%

Perl

4%

Ob...
Top Languages in Github
Javascript

21%

Ruby

12%

Java

8%

Python

8%

Shell

8%

PHP

7%

C

6%

C++

5%

Perl

4%

Ob...
What does the logo mean?
界 Kingdom

動物界 Animalia

⾨門 Phylum

脊索動物⾨門 Chordata

綱 Class

爬蟲科 Reptilia

⺫⽬目 Order

有鱗⺫⽬目 Squamata

科 Family

蟒科 Python...
http://wallpapers.free-review.net/15__Tree_python.htm
http://wallpapers.free-review.net/15__Tree_python.htm
More About Python...
More About Python...
Interpreted Language

Do not need to compile!
Compiled Language

compiler

execute
Interpreted Language
But, interpret in execution time.
execute

And, it would be slow...
More About Python...
Object-Oriented Language

Everything in Python is object!
number
string
list
function

Object
number
string
list
function

Object
overloading
inheritance
multiple inheritance
polymorphism
More About Python...
Imperative Programming
Generic Programming
Functional Programming
Philosophy
Philosophy
There should be one—
and preferably only one
—obvious way to do it.
Philosophy
There should be one—
and preferably only one
—obvious way to do it.
Zen of Python
$
Zen of Python
$ python -ic “”
Zen of Python
$ python -ic “”
>>>
Zen of Python
$ python -ic “”
>>> import this
Zen of Python
one
There
temptation to guess. and refuse
In --obviousbe
Unless
Errors
Althoughcasesbetter
breakis betternev...
Current Situation
Current Situation

Python 2.x

Python 3.x
Current Situation

Python 2.x

Python 3.x

Coexist!
Current Situation

Python 2.x

Python 3.x

Coexist!
Current Situation
backwards-incompatible

Python 2.x

Python 3.x

Coexist!
Python 2.x

Python 3.x

2.7.x is the latest version

under development

more 3-party library

2to3.py

built-in on many OS...
Python 3 的新特性
http://www.ibm.com/developerworks/cn/linux/l-python3-1/
Python 2.x
Today, Let’s Talk About

Python 2.x
Environment
Environment
For Unix-like OS User,

Python 2.x is Built-in!
Environment
For Windows User,

Download From
http://www.python.org/download/
if you want to launch Python in command line,...
Check Version of Python
$
Check Version of Python
$ python --version
Check Version of Python
$ python --version
Python 2.7.5
Check Version of Python
$ python --version
Python 2.7.5

2.7.5 is released on May 15, 2013
Check Version of Python
$
Check Version of Python
$ python
Check Version of Python
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang...
Check Version of Python
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang...
Interactive Shell
$
Interactive Shell
$ python
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$
Interactive Shell
$ python
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
$ python
Python 2.7.5 (default, May 20 2013,
23:41:46)
[GCC 4.2.1 Compatible Apple LLVM 4.2
(clang-425.0...
Interactive Shell
Python 2.7.5 (default, May 20 2013,
$ python
23:41:46)
Python 2.7.5 (default, May 20 2013,
[GCC 4.2.1
23...
Interactive Shell
Python 2.7.5 (default, May 20 2013,
$ python
23:41:46)
Python 2.7.5 (default, May 20 2013,
[GCC 4.2.1
23...
Interactive Shell
23:41:46)
Python 2.7.5 (default, May 20 2013,
$ python
[GCC 4.2.1
23:41:46) Compatible May LLVM 4.2
Pyth...
Interactive Shell
23:41:46)
Python 2.7.5 (default, May 20 2013,
$ python
[GCC 4.2.1
23:41:46) Compatible May LLVM 4.2
Pyth...
Interactive Shell
(clang-425.0.28)] on darwin
23:41:46)
Python 2.7.5 (default, May 20 2013,
$ python
Type "help", "copyrig...
Interactive Shell
(clang-425.0.28)] on darwin
23:41:46)
Python 2.7.5 (default, May 20 2013,
$ python
Type "help", "copyrig...
Interactive Shell
Type "help", "copyright",
(clang-425.0.28)] on darwin20 2013,
23:41:46)
Python 2.7.5 (default, May"credi...
Interactive Shell
Type "help", "copyright",
(clang-425.0.28)] on darwin20 2013,
23:41:46)
Python 2.7.5 (default, May"credi...
Interactive Shell
"license"
Type "help", more information.
(clang-425.0.28)] on darwin
23:41:46)
Python 2.7.5 "copyright",...
Interactive Shell
>>>
"license"
Typey"help",
(clang-425.0.28)] information.
23:41:46) for moreon darwin
Python=2.7.5 "copy...
Interactive Shell
>>>
"license"
Typey"help",
(clang-425.0.28)] information.
23:41:46) for moreon darwin
Python=2.7.5 "copy...
Interactive Shell
>>> x + 200
"license"
Typey"help", more information.
(clang-425.0.28)] on darwin
23:41:46)
Python=2.7.5 ...
Hello World!
Hello World!
if __name__ == “__main__”:
print “Hello World!”

helloworld.py
Hello World!
$
Hello World!
$ python helloworld.py
Hello World!
$ python helloworld.py
Hello World!
$
A Python Code
A Python Code
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {2}...
script language
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {...
script language
$
script language
$ python 9x9table.py
script language
8
7
6
5
4
3
2
$
8
7
6
5
4
3
2
8
7
6
5
4
3
2
9
8
7
6
5
4
3
2
9
8
7
6
5
4
3
2
9
8
7
6
5
4
3
2
9
8
7
6
5
4
3
...
If you need a main function
as entry point,

if __name__ == “__main__”:
print “Hello World!”
If you need a main function
as entry point,

if __name__ == “__main__”:
print “Hello World!”
If you need a main function
as entry point,

if __name__ == “__main__”:
print “Hello World!”

and write all statements aft...
variable
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {2}".for...
variable
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {2}".for...
scope
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {2}".format...
scope
def mul(x, y):
ret = x * y
return ret
for i in range(10)[2:]:
for j in range(10)[1:]:
print "{0} x {1} = {2}".format...
You can use

to identify scopes.
You can use
one space
two spaces
three spaces
four spaces
lots of spaces

to identify scopes.
You can use
one space

one tab

two spaces

two tabs

three spaces

three tabs

four spaces

four tabs

lots of spaces

lo...
But, you should unify the style!
Built-in Data Type
Null
>>>

None
Null
>>> None

None
Null
None

>>> None
>>>
Boolean
>>>

True
False
Boolean
>>> 1 == 1

True
False
Boolean
True
False

>>> 1 == 1
True
>>>
Boolean
True
False

>>> 1 == 1
True
>>> 1 != 1
Boolean
True
False

>>> 1 == 1
True
>>> 1 != 1
False
>>>
Boolean
True
False

>>> 1 == 1
True
>>> 1 != 1
False
>>> True
Boolean
True
False

>>> 1 == 1
True
>>> 1 != 1
False
>>> True
True
>>>
Boolean
True
False

>>> 1 == 1
True
>>> 1 != 1
False
>>> True
True
>>> False
Boolean
True
False

True
>>> 1 == 1
>>>
True1 != 1
False
>>> 1 != 1
>>> True
False
True
>>> True
>>>
TrueFalse
False
>>> F...
Boolean
>>>

True
False
Boolean
upper case
>>>

True
False
Boolean
upper case
>>> true

True
False
Boolean
upper case

True
False

>>> true
Traceback (most recent
call last):
File "<input>", line
1, in <module>
NameError:...
Initialization / Conversion
>>>

True
False
Initialization / Conversion
>>> bool(1)

True
False
Initialization / Conversion
True
False

>>> bool(1)
True
>>>
Initialization / Conversion
True
False

>>> bool(1)
True
>>> bool(True)
Initialization / Conversion
True
False

>>> bool(1)
True
>>> bool(True)
True
>>>
Initialization / Conversion
True
False

>>> bool(1)
True
>>> bool(True)
True
>>> bool()
Initialization / Conversion
True
False

>>> bool(1)
True
>>> bool(True)
True
>>> bool()
False
>>>
Logical Operators
>>>

and

and

or

or

not

not
Logical Operators
>>> (1 == 1) and True

and

and

or

or

not

not
Logical Operators
and

and

or

or

not

not

>>> (1 == 1) and True
True
>>>
Logical Operators
and

and

or

or

not

not

>>> (1 == 1) and True
True
>>> (1 == 1) or False
Logical Operators
and

and

or

or

not

not

>>> (1 == 1) and True
True
>>> (1 == 1) or False
True
>>>
Logical Operators
and

and

or

or

not

not

>>> (1 == 1) and True
True
>>> (1 == 1) or False
True
>>> not (1 == 1)
Logical Operators
and

and

or

or

not

not

>>> (1 == 1) and True
True
>>> (1 == 1) or False
True
>>> not (1 == 1)
False...
Numbers
int
(integer)

long
(long integer)

float
(real number)

complex
(complex number)

10

10L

100.0

3 + 2j

-789

-7...
Initialization / Conversion
data type

initial
>>>

int

int(x)

long

long(x)

float

float(x)

complex

complex(x)
comple...
Initialization / Conversion
data type

initial
>>> int(10)

int

int(x)

long

long(x)

float

float(x)

complex

complex(x...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>>

int

int(x)

long

long(x)

float

float(x)

complex

co...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>> int(“100”)

int

int(x)

long

long(x)

float

float(x)

...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>> int(“100”)
100
>>>

int

int(x)

long

long(x)

float

fl...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>> int(“100”)
100
>>> complex(10)

int

int(x)

long

long(...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>> int(“100”)
100
>>> complex(10)
(10+0j)
>>>

int

int(x)
...
Initialization / Conversion
data type

initial
>>> int(10)
10
>>> int(“100”)
100
>>> complex(10)
(10+0j)
>>> complex(10, 3...
Initialization / Conversion
data type

initial
10
>>> int(10)
>>>
10 int(“100”)
100
>>> int(“100”)
>>>
100 complex(10)
(10...
Initialization / Conversion
data type

initial
10
>>> int(10)
>>>
10 int(“100”)
100
>>> int(“100”)
>>>
100 complex(10)
(10...
Initialization / Conversion
data type

initial
100
10
>>> int(10)
>>> complex(10)
10 int(“100”)
(10+0j)
100
>>> int(“100”)...
Arithmetic Operators
+

addition

-

subtraction

*

multiplication

/

division

%

modular

**

exponential

//

floor di...
Arithmetic Operators
+

addition

-

subtraction

*

multiplication

/

division

%

modular

**

exponential

//

floor di...
Arithmetic Operators
+

addition

-

subtraction

*

multiplication

/

division

%

modular

**

exponential

//

floor di...
Arithmetic Operators
+

addition

-

subtraction

*

multiplication

/

division

%

modular

**

exponential

//

floor di...
Arithmetic Operators
+

addition

-

subtraction

*

multiplication

/

division

%

modular

**

exponential

//

floor di...
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>>
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
1
>>>
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
1
>>> 1 << 10
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
1
>>> 1 << 10
1024
>>...
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
1
>>> 1 << 10
1024
>>...
Bitwise Operators
&

and

|

or

^

exclusion or

>>

shift right

<<

shift left

~

not

>>> 3 & 1
1
>>> 1 << 10
1024
>>...
Comparison Operators
>
>=
<
<=
==
!=

greater than
greater than or equal to
less than
less than or equal to
equal to
not e...
String
Contents are
surrounded by
single quote or
double quote.

>>>
String
Contents are
surrounded by
single quote or
double quote.

>>> “Hello World”
String
Contents are
surrounded by
single quote or
double quote.

>>> “Hello World”
‘Hello World’
>>>
String
Contents are
surrounded by
single quote or
double quote.

>>> “Hello World”
World!”
‘Hello World’
>>> ‘Hello World!...
String
Contents are
surrounded by
single quote or
double quote.

>>> “Hello World”
World!”
‘Hello World’
>>> ‘Hello World!...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>>
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

>>> “““Hello
... World!”””
‘Hell...
Cross-line String
Contents are
surrounded by
three single
quotes or three
double quotes.

... World!”””
>>> “““Hello
‘Hell...
Initialization / Conversion
>>>
Initialization / Conversion
>>> str(“I’m string”)
Initialization / Conversion
>>> str(“I’m string”)
“I’m string”
>>>
Initialization / Conversion
>>> str(“I’m string”)
“I’m string”
>>> str(100)
Initialization / Conversion
>>> str(“I’m string”)
“I’m string”
>>> str(100)
‘100’
>>>
Initialization / Conversion
>>> str(“I’m string”)
“I’m string”
>>> str(100)
‘100’
>>> str(complex(10, 3))
Initialization / Conversion
>>> str(“I’m string”)
“I’m string”
>>> str(100)
‘100’
>>> str(complex(10, 3))
‘(10+3j)’
>>>
Operators
>>>

+

concatenate

*

repeat
Operators
>>> x = “abc”

+

concatenate

*

repeat
Operators
>>> x = “abc”
>>>

+

concatenate

*

repeat
Operators
>>> x = “abc”
>>> ‘(’ + x + ‘)’

+

concatenate

*

repeat
Operators

+

concatenate

*

repeat

>>> x = “abc”
>>> ‘(’ + x + ‘)’
‘(abc)’
>>>
Operators

+

concatenate

*

repeat

>>> x = “abc”
>>> ‘(’ + x + ‘)’
‘(abc)’
>>> x * 3
Operators

+

concatenate

*

repeat

>>> x = “abc”
>>> ‘(’ + x + ‘)’
‘(abc)’
>>> x * 3
‘abcabcabc’
>>>
Operators

+

concatenate

*

repeat

>>> x = “abc”
>>> ‘(’ + x + ‘)’
‘(abc)’
>>> x * 3
‘abcabcabc’
>>> ‘(’ + x * 3 + ‘)’
Operators

+

concatenate

*

repeat

>>> x = “abc”
‘abc’
>>> ‘(’ + x + ‘)’
‘(abc)’
>>> x * 3
‘abcabcabc’
>>> ‘(’ + x * 3 ...
Operators

+

concatenate

*

repeat

>>> x = “abc”
‘abc’
>>> ‘(’ + x + ‘)’
‘(abc)’
>>> x * 3
‘abcabcabc’
>>> ‘(’ + x * 3 ...
Operators

+

concatenate

*

repeat

‘(abc)’ ‘abc’
>>> x = “abc”
>>> ‘(’ + x + ‘)’
x * 3
‘abcabcabc’
‘(abc)’
>>> ‘(’ + x ...
Access Character
>>>
Access Character
>>> x = ‘0123456789’
Access Character
>>> x = ‘0123456789’
>>>
Access Character
>>> x = ‘0123456789’
>>> x[1]
Access Character
>>> x = ‘0123456789’
>>> x[1]
‘1’
>>>
Access Character
>>> x = ‘0123456789’
>>> x[1]
‘1’
>>> x[1] = ‘0’
Access Character
>>> x = ‘0123456789’
>>> x[1]
‘1’
>>> x[1] = ‘0’
>>>
Access Character
>>>
>>>
‘1’
>>>
>>>

x = ‘0123456789’
x[1]
x[1] = ‘0’
x
Access Character
>>> x = ‘0123456789’
>>> x[1]
‘1’
>>> x[1] = ‘0’
>>> x
‘0023456789’
>>>
substring
>>>

[start:end(:step)]
substring
>>>

[start:end(:step)]
default value
[0:length(:1)]
substring
>>> x = “0123456789”

[start:end(:step)]
default value
[0:length(:1)]
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>>
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>>
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>> x[:]
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>> x[:]
‘012345678...
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>> x[:]
‘012345678...
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>> x[:]
‘012345678...
substring
[start:end(:step)]
default value
[0:length(:1)]

>>> x = “0123456789”
>>> x[::]
‘0123456789’
>>> x[:]
‘012345678...
substring
[start:end(:step)]
default value
[0:length(:1)]

‘0123456789’
>>> x = “0123456789”
>>> x[::]
x[:]
‘0123456789’
>...
substring
[start:end(:step)]
default value
[0:length(:1)]

‘0123456789’
>>> x = “0123456789”
>>> x[::]
x[:]
‘0123456789’
>...
substring
[start:end(:step)]
default value
[0:length(:1)]

‘0123456789’
>>> x = “0123456789”
>>> x[::]
x[1:4]
x[:]
‘123’
‘...
substring
[start:end(:step)]
default value
[0:length(:1)]

‘0123456789’
>>> x = “0123456789”
>>> x[::]
x[1:4]
x[:]
‘123’
‘...
substring
[start:end(:step)]
default value
[0:length(:1)]

‘123’
‘0123456789’
>>> x = “0123456789”
>>> x[::]
x[1:-1]
x[1:4...
length of string
>>>

len(string)
length of string
>>> x = ‘0123456789’

len(string)
length of string
len(string)

>>> x = ‘0123456789’
>>>
length of string
len(string)

>>> x = ‘0123456789’
>>> len(x)
length of string
len(string)

>>> x = ‘0123456789’
>>> len(x)
10
>>>
length of string
len(string)

>>> x = ‘0123456789’
>>> len(x)
10
>>> len(x[::2])
length of string
len(string)

>>> x = ‘0123456789’
>>> len(x)
10
>>> len(x[::2])
5
>>>
List
Contents are
surrounded by
square brackets
and separate by
comma.

>>>
List
Contents are
surrounded by
square brackets
and separate by
comma.

>>> [“aaa”, “bbb”, 1, 2]
List
Contents are
surrounded by
square brackets
and separate by
comma.

>>> [“aaa”, “bbb”, 1, 2]
[‘aaa’, ‘bbb’, 1, 2]
>>>
Initialization / Conversion
>>>
Initialization / Conversion
>>> list([1, 2, 3])
Initialization / Conversion
>>> list([1, 2, 3])
[1, 2, 3]
>>>
Initialization / Conversion
>>> list([1, 2, 3])
[1, 2, 3]
>>> list(“abc”)
Initialization / Conversion
>>> list([1, 2, 3])
[1, 2, 3]
>>> list(“abc”)
[‘a’, ‘b’, ‘c’]
>>>
Operators
>>>

+

append

*

repeat
Operators
>>> x = [1, 2, 3]

+

append

*

repeat
Operators
>>> x = [1, 2, 3]
>>>

+

append

*

repeat
Operators
>>> x = [1, 2, 3]
>>> y = [‘a’, ‘b’]

+

append

*

repeat
Operators

+

append

*

repeat

>>> x = [1, 2, 3]
>>> y = [‘a’, ‘b’]
>>>
Operators

+

append

*

repeat

>>> x = [1, 2, 3]
>>> y = [‘a’, ‘b’]
>>> x * 2
Operators

+

append

*

repeat

>>>
>>>
>>>
[1,
>>>

x = [1, 2, 3]
y = [‘a’, ‘b’]
x * 2
2, 3, 1, 2, 3]
Operators

+

append

*

repeat

>>>
>>>
>>>
[1,
>>>

x = [1, 2, 3]
y = [‘a’, ‘b’]
x * 2
2, 3, 1, 2, 3]
x + y
Operators

+

append

*

repeat

>>>
>>>
>>>
[1,
>>>
[1,
>>>

x = [1, 2, 3]
y = [‘a’, ‘b’]
x * 2
2, 3, 1, 2, 3]
x + y
2, 3...
Access Element
>>>
Access Element
>>> x = [1, 2, 3, 4, 5]
Access Element
>>> x = [1, 2, 3, 4, 5]
>>>
Access Element
>>> x = [1, 2, 3, 4, 5]
>>> x[1]
Access Element
>>> x = [1, 2, 3, 4, 5]
>>> x[1]
2
>>>
Access Element
>>> x = [1, 2, 3, 4, 5]
>>> x[1]
2
>>> x[1] = ‘0’
Access Element
>>> x = [1, 2, 3, 4, 5]
>>> x[1]
2
>>> x[1] = ‘0’
>>>
Access Element
>>>
>>>
2
>>>
>>>

x = [1, 2, 3, 4, 5]
x[1]
x[1] = ‘0’
x
Access Element
>>>
>>>
2
>>>
>>>
[1,
>>>

x = [1, 2, 3, 4, 5]
x[1]
x[1] = ‘0’
x
‘0’, 3, 4, 5]
Slice
>>>

[start:end(:step)]
Slice
>>>

[start:end(:step)]
default value
[0:length(:1)]
Slice
>>> x = [1, 2, 3, 4, 5]

[start:end(:step)]
default value
[0:length(:1)]
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>> x = [1, 2, 3, 4, 5]
>>>
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>> x = [1, 2, 3, 4, 5]
>>> x[::]
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>> x = [1, 2, 3, 4, 5]
>>> x[::]
[1, 2, 3, 4, 5]
>>>
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>>
>>>
[1,
>>>

x = [1, 2, 3, 4, 5]
x[::]
2, 3, 4, 5]
x[:]
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>>
>>>
[1,
>>>
[1,
>>>

x = [1, 2, 3, 4, 5]
x[::]
2, 3, 4, 5]
x[:]...
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>>
>>>
[1,
>>>
[1,
>>>

x = [1, 2, 3, 4, 5]
x[::]
2, 3, 4, 5]
x[:]...
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>>
>>>
[1,
>>>
[1,
>>>
[2,
>>>

x = [1, 2, 3, 4, 5]
x[::]
2, 3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

>>>
>>>
[1,
>>>
[1,
>>>
[2,
>>>

x = [1, 2, 3, 4, 5]
x[::]
2, 3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

[1,
>>>
>>>
[1,
>>>
[2,
[1,
>>>
[2,
>>>

2, [1, 5]
x =3, 4,2, 3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

[1,
>>>
>>>
[1,
>>>
[2,
[1,
>>>
[2,
>>>

2, [1, 5]
x =3, 4,2, 3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

[1,
>>>
>>>
[2,
[1,
>>>
[2,
[1,
>>>
[1,
[2,
>>>

2, [1, 5]
x =3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

[1,
>>>
>>>
[2,
[1,
>>>
[2,
[1,
>>>
[1,
[2,
>>>

2, [1, 5]
x =3, 4,...
Slice
[start:end(:step)]
default value
[0:length(:1)]

[2,
[1,
>>>
>>>
[2,
[1,
>>>
[2,
[1,
>>>
[5,
[1,
[2,
>>>

3]
2, [1, ...
length of list
>>>

len(list)
length of list
>>> x = [1, 2, 3, 4, 5]

len(list)
length of list
len(list)

>>> x = [1, 2, 3, 4, 5]
>>>
length of list
len(list)

>>> x = [1, 2, 3, 4, 5]
>>> len(x)
length of list
len(list)

>>> x = [1, 2, 3, 4, 5]
>>> len(x)
5
>>>
length of list
len(list)

>>> x = [1, 2, 3, 4, 5]
>>> len(x)
5
>>> len(x[::2])
length of list
len(list)

>>> x = [1, 2, 3, 4, 5]
>>> len(x)
5
>>> len(x[::2])
3
>>>
Tuple
>>>

Immutable List
Tuple
>>> (1, ‘aaa’, 2)

Immutable List
Tuple
>>> (1, ‘aaa’, 2)
(1, ‘aaa’, 2)
>>>

Immutable List
Tuple
>>> (1, ‘aaa’, 2)
(1, ‘aaa’, 2)
>>> 1, ‘aaa’, 2

Immutable List
Tuple

Immutable List

>>>
(1,
>>>
(1,
>>>

(1, ‘aaa’, 2)
‘aaa’, 2)
1, ‘aaa’, 2
‘aaa’, 2)
Tuple

Immutable List

>>>
(1,
>>>
(1,
>>>

(1, ‘aaa’, 2)
‘aaa’, 2)
1, ‘aaa’, 2
‘aaa’, 2)
x = (1, ‘aaa’, 2)
Tuple

Immutable List

>>>
(1,
>>>
(1,
>>>
>>>

(1, ‘aaa’, 2)
‘aaa’, 2)
1, ‘aaa’, 2
‘aaa’, 2)
x = (1, ‘aaa’, 2)
Tuple

Immutable List

>>>
(1,
>>>
(1,
>>>
>>>

(1, ‘aaa’, 2)
‘aaa’, 2)
1, ‘aaa’, 2
‘aaa’, 2)
x = (1, ‘aaa’, 2)
x[1] = 3
Tuple

Immutable List

>>> (1, ‘aaa’, 2)
x[1] = 3
Traceback 2)
(1, ‘aaa’,(most recent
call last):
>>> 1, ‘aaa’, 2
(1, ‘aaa...
Tuple

Immutable List

Traceback=(most recent
>>> (1, ‘aaa’, 2)
x[1]
3
call last):
Traceback 2)
(1, ‘aaa’,(most recent
cal...
Initialization / Conversion
>>>
Initialization / Conversion
>>> tuple([1, 2, 3])
Initialization / Conversion
>>> tuple([1, 2, 3])
(1, 2, 3)
>>>
Access Element
>>>
Access Element
>>> x = (1, 2, 3)
Access Element
>>> x = (1, 2, 3)
>>>
Access Element
>>> x = (1, 2, 3)
>>> x[1]
Access Element
>>> x = (1, 2, 3)
>>> x[1]
2
>>>
Access Element
>>> x = (1, 2, 3)
>>> x[1]
2
>>> a, b, c = x
Access Element
>>> x = (1, 2, 3)
>>> x[1]
2
>>> a, b, c = x
>>>
Access Element
>>>
>>>
2
>>>
>>>

x = (1, 2, 3)
x[1]
a, b, c = x
a
Access Element
>>>
>>>
2
>>>
>>>
1
>>>

x = (1, 2, 3)
x[1]
a, b, c = x
a
Access Element
>>>
>>>
2
>>>
>>>
1
>>>

x = (1, 2, 3)
x[1]
a, b, c = x
a
b
Access Element
>>>
2
>>>
>>>
2
>>>
1
>>>
>>>
1
2
>>>
>>>

x[1]
x = (1, 2, 3)
x[1]
a, b, c = x
a
a, b, c = x
a
b
b
Access Element
>>>
2
>>>
>>>
2
>>>
1
>>>
>>>
1
2
>>>
>>>

x[1]
x = (1, 2, 3)
x[1]
a, b, c = x
a
a, b, c = x
a
b
b
c
Access Element
>>>
2
>>>
1
>>>
2
>>>
2
1
>>>
>>>
1
3
2
>>>
>>>

a,
x[1](1, =
x =b, c 2,x3)
a
x[1]
a, b, c = x
b
a
a, b, c ...
length of tuple
>>>

len(tuple)
length of tuple
>>> x = 1, 2, 3, 4, 5

len(tuple)
length of tuple
len(tuple)

>>> x = 1, 2, 3, 4, 5
>>>
length of tuple
len(tuple)

>>> x = 1, 2, 3, 4, 5
>>> len(x)
length of tuple
len(tuple)

>>> x = 1, 2, 3, 4, 5
>>> len(x)
5
>>>
Dictionary
key-value relation

key

value

>>>
Dictionary
key-value relation

key

value

>>>
Dictionary
key-value relation

key

value

>>> x = dict()
Dictionary
key-value relation

key

value

>>> x = dict()
>>>
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>>
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>> x[111] = ‘aaa’
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>> x[111] = ‘aaa’
>>>
Dictionary
key-value relation

key

value

>>>
>>>
>>>
>>>

x = dict()
x[‘abc’] = 123
x[111] = ‘aaa’
x
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>> x[111] = ‘aaa’
>>> x
{‘abc’: 123, 111: ‘a...
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>> x[111] = ‘aaa’
>>> x
{‘abc’: 123, 111: ‘a...
Dictionary
key-value relation

key

value

>>> x = dict()
>>> x[‘abc’] = 123
>>> x[111] = ‘aaa’
>>> x
{‘abc’: 123, 111: ‘a...
Initialization / Conversion
>>>
Initialization / Conversion
>>> dict()
Initialization / Conversion
>>> dict()
{}
>>>
Initialization / Conversion
>>> dict()
{}
>>> dict(one=1, two=2)
Initialization / Conversion
>>> dict()
{}
>>> dict(one=1, two=2)
{‘one’: 1, ‘two’: 2}
>>>
Initialization / Conversion
>>> dict()
{}
>>> dict(one=1, two=2)
{‘one’: 1, ‘two’: 2}
>>> dict([('two', 2),
(‘one’: 1)])
Initialization / Conversion
>>> dict()
{}
>>> dict(one=1, two=2)
{‘one’: 1, ‘two’: 2}
>>> dict([('two', 2),
(‘one’: 1)])
{...
Initialization / Conversion
{}
>>> dict()
>>>
{} dict(one=1, two=2)
{‘one’: 1, ‘two’: 2}
>>> dict(one=1, two=2)
>>> dict([...
Initialization / Conversion
{‘one’: 1,
{}
>>> dict() ‘two’: 2}
>>> dict([('two', 2),
{} dict(one=1, two=2)
(‘one’: 1, ‘two...
number of dictionary
>>>

len(dict)
number of dictionary
len(dict)

>>> x = {‘one’: 1,
‘two’: 2}
number of dictionary
len(dict)

>>> x = {‘one’: 1,
‘two’: 2}
>>>
number of dictionary
len(dict)

>>> x = {‘one’: 1,
‘two’: 2}
>>> len(x)
number of dictionary
len(dict)

>>> x = {‘one’: 1,
‘two’: 2}
>>> len(x)
2
>>>
Control
Condition
>>>
Condition
>>> x = 100
Condition
>>> x = 100
>>>
Condition
>>> x = 100
>>> if x > 100:
Condition
>>> x = 100
>>> if x > 100:
...
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
...
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
... elif x < 100:
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
... elif x < 100:
...
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
... elif x < 100:
...
x = x - 10
Condition
>>> x = 100
>>> if x > 100:
...
x = x + 10
... elif x < 100:
...
x = x - 10
...
Condition
>>>
>>>
...
...
...
...

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
Condition
>>>
>>>
...
...
...
...
...

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
Condition
>>>
>>>
...
...
...
...
...

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
Condition
>>>
>>>
...
...
...
...
...
...

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
Condition
>>>
>>>
...
...
...
...
...
...
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
Condition
>>>
>>>
...
...
...
...
...
...
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
x
Condition
>>>
>>>
...
...
...
...
...
...
>>>
0
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
x
Condition
>>>
>>>
...
...
...
...
...
...
>>>
0
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
x
Condition
>>>
>>>
...
...
...
...
...
...
>>>
0
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0
x...
Condition
>>>
>>>
...
...
...
...
...
...
>>>
0
>>>

x = 100
if x > 100:
x = x + 10
elif x < 100:
x = x - 10
else:
x = 0

...
Loop
>>>
Loop
>>> i = 0
Loop
>>> i = 0
>>>
Loop
>>> i = 0
>>> while i < 3:
Loop
>>> i = 0
>>> while i < 3:
...
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
...
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
...
print i
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
...
print i
...
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
...
print i
...
1
2
3
>>>
Loop
>>> i = 0
>>> while i < 3:
...
i = i + 1
...
print i
...
1
2
3
>>>

no do-while statement in Python
Traversal Sequence
>>>
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>>
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
print i
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
print i
...
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
print i
...
1
2
3
4
5
>>>
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
print i
...
1
2
3
4
5
>>>
Traversal Sequence
>>> x = [1, 2, 3, 4, 5]
>>> for i in x:
...
print i
...
1
2
3
4
5
>>>

must be a iterable object
Addition for Loop
skip remaining statement and
continue
continue loop
>>>
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
...
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
...
continue
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
...
continue
....
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
...
continue
....
Addition for Loop
skip remaining statement and
continue
continue loop
>>> for i in range(5):
...
if i == 2:
...
continue
....
Addition for Loop
skip remaining statement and
continue
continue loop
...
>>> for ifin range(5):
i i == 2:
...
if icontinu...
Addition for Loop
break
>>>

exit from loop
Addition for Loop
break

exit from loop

>>> for i in range(5):
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
break
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
break
...
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
break
...
print i
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
break
...
print i
...
Addition for Loop
break

exit from loop

>>> for i in range(5):
...
if i == 2:
...
break
...
print i
...
0
1
>>>
Addition for Loop
else
>>>

do something after unbroken
loop
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
...
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
... else:
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
... else:
...
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
... else:
...
print “done”
Addition for Loop
else

do something after unbroken
loop

>>> for i in range(3):
...
print i
... else:
...
print “done”
.....
Addition for Loop
else

do something after unbroken
loop

...
>>> for i in range(3):
print i
... else:
print i
... else:
p...
Standard I/O
Evaluated Input
input
>>>

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()
1

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()
1
1
>>>

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()
1
1
>>> input()

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()
1
1
>>> input()
1 + 2

read a string can be evaluated
return an evaluated object
Evaluated Input
input
>>> input()
1
1
>>> input()
1 + 2
3
>>>

read a string can be evaluated
return an evaluated object
Evaluated Input
read a string can be evaluated
return an evaluated object

input
>>>
1
1
>>>
1 +
3
>>>

input()

input()
2...
Evaluated Input
read a string can be evaluated
return an evaluated object

input
>>>
1
1
>>>
1 +
3
>>>
5.0

input()

input...
Evaluated Input
read a string can be evaluated
return an evaluated object

input
1
>>>
1
>>>
1
1 +
>>>
3
1 +
>>>
3
5.0
>>>...
Evaluated Input
read a string can be evaluated
return an evaluated object

input
1
>>>
>>>
1
>>>
1 +
3
1 +
>>>
>>>
3
1 +
5...
Evaluated Input
input
1
>>> input()
>>> input()
1
>>> 2
1 + input()
3
1 + 2
>>> input()
>>> input()
3
1 + 2
5.0 / 2
>>> in...
Evaluated Input
input
1 + 2
>>> input()
3
>>> input()
1
>>> 2
1 + input()
5.0 /
3
1 + 2 2
>>> input()
2.5
>>> input()
3
1 ...
Evaluated Input
input
1 + 2
>>> input()
3
>>> input()
1
>>> 2
1 + input()
5.0 /
3
1 + 2 2
>>> input()
2.5
>>> input()
3
1 ...
Evaluated Input
input
3
1 + 2
>>> input()
3
>>> input()
1
5.0 /
>>> 2 2
1 + input()
2.5
5.0 /
3
1 + 2 2
>>> input()
2.5
>>...
Evaluated Input
input
5.0 /
3
1 + 2 2
>>> input()
2.5
3
>>> input()
1
5.0 /
>>> 2 2
1 + input()
“aaa
2.5
5.0 / 2
3
1 + 2bb...
Evaluated Input
input
5.0 /
3
1 + 2 2
>>> input()
2.5
3
>>> input()
1
5.0 /
>>> 2 2
1 + input()
“aaa
2.5
5.0 / 2
3
1 + 2bb...
Evaluated Input
input
2.5
5.0 /
3
1 + 2 2
>>> input()
2.5
3
>>> input()
1
“aaa
5.0 / 2
>>> 2bbb”
1 + input()
‘aaa
“aaa 2
2...
Evaluated Input
input

read a string can be evaluated
return an evaluated object

2.5
5.0 /
3
1 + 2 2
>>> input()
2.5
3
>>...
Raw Input
read a string
raw_input()
return a string
>>>
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>>
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>> raw_input()
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>> raw_input()
1 + 2
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>> raw_input()
1 + 2
‘1 + 2’
>>>
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>> raw_input()
1 + 2
‘1 + 2’
>>> raw_input()
Raw Input
read a string
raw_input()
return a string
>>> raw_input()
1
‘1’
>>> raw_input()
1 + 2
‘1 + 2’
>>> raw_input()
5....
Raw Input
read a string
raw_input()
return a string
1
>>> raw_input()
‘1’
1
>>>
‘1’ raw_input()
1 + 2
>>> raw_input()
‘1
1...
Raw Input
read a string
raw_input()
return a string
‘1’
1
>>> raw_input()
>>>
‘1’ raw_input()
1
1 +
>>> 2
‘1’ raw_input()
...
Raw Input
read a string
raw_input()
return a string
‘1’
1
>>> raw_input()
>>>
‘1’ raw_input()
1
1 +
>>> 2
‘1’ raw_input()
...
Raw Input
read a string
raw_input()
return a string
‘1’
1 + 2
>>> raw_input()
‘1
>>>
‘1’ 2’
1 +raw_input()
1 +
>>> 2
‘1’ r...
Raw Input
read a string
raw_input()
return a string
‘1’
1 + 2
>>> raw_input()
‘1
>>>
‘1’ 2’
1 +raw_input()
1 +
>>> 2
‘1’ r...
Raw Input
read a string
raw_input()
return a string
‘1
‘1’
1 + 22’
>>>+raw_input()
‘1
>>>
‘1’ 2’
1 +raw_input()
5.0
1 + /
...
Raw Input
read a string
raw_input()
return a string
5.0
‘1
‘1’ / 2
1 + 22’
>>>+raw_input()
‘5.0
‘1
>>> /
‘1’ 2’2’
1 +raw_i...
Raw Input
read a string
raw_input()
return a string
5.0
‘1
‘1’ / 2
1 + 22’
>>>+raw_input()
‘5.0
‘1
>>> /
‘1’ 2’2’
1 +raw_i...
Raw Input
read a string
raw_input()
return a string
‘5.0
5.0
‘1
‘1’ //2
1 + 22’2’
>>>+raw_input()
‘5.0
‘1
>>> /
‘1’ 2’2’
1...
Raw Input
read a string
raw_input()
return a string
“aaa
‘5.0
5.0 bbb”
‘1
‘1’ //2
1 + 22’2’
>>>+raw_input()
‘“aaa
‘5.0
‘1
...
Output
print
>>>

print object to standard output
Output
print

print object to standard output

>>> print “Hello World!”
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>>
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Hello Wor...
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Hello Wor...
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Hello Wor...
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Hello Wor...
Output
print

print object to standard output

>>> print “Hello World!”
Hello World!
>>> print “Hello”, “World!”
Hello Wor...
Custom Function
Define a Function
>>>
Define a Function
>>> def SQ(x):
Define a Function
>>> def SQ(x):
...
Define a Function
>>> def SQ(x):
...
return x * x
Define a Function
>>> def SQ(x):
...
return x * x
...
Define a Function
>>> def SQ(x):
...
return x * x
...
>>>
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
100
>>>
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
100
>>>
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
100
>>>

function name
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
100
>>>

function name

parameter
Define a Function
>>> def SQ(x):
...
return x * x
...
>>> SQ(10)
100
>>>

function name

parameter

function content
Lambda Function
>>>
Lambda Function
>>> CUBE = lambda k: k * k * k
Lambda Function
>>> CUBE = lambda k: k * k * k
>>>
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>>
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>> (lambda x, y: x * y)(3, 4)
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>> (lambda x, y: x * y)(3, 4)
12
>>>
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>> (lambda x, y: x * y)(3, 4)
12
>>>
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>> (lambda x, y: x * y)(3, 4)
12
>>>

parameter
Lambda Function
>>> CUBE = lambda k: k * k * k
>>> CUBE(10)
1000
>>> (lambda x, y: x * y)(3, 4)
12
>>>

return value
param...
Built-in Function
range
>>>
range
>>> range(10)
range
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
range
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(3, 10)
range
>>>
[0,
>>>
[3,
>>>

range(10)
1, 2, 3, 4, 5, 6, 7, 8, 9]
range(3, 10)
4, 5, 6, 7, 8, 9]
range
>>>
[0,
>>>
[3,
>>>

range(10)
1, 2, 3, 4, 5, 6, 7, 8, 9]
range(3, 10)
4, 5, 6, 7, 8, 9]
range(1, 10, 2)
range
>>>
[0,
>>>
[3,
>>>
[1,
>>>

range(10)
1, 2, 3, 4, 5, 6, 7, 8, 9]
range(3, 10)
4, 5, 6, 7, 8, 9]
range(1, 10, 2)
3, ...
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Python @NCKU CSIE
Upcoming SlideShare
Loading in …5
×

Python @NCKU CSIE

1,570 views

Published on

National Cheng Kung University
2013 Programming Language
Talk About Python

Published in: Education, Technology
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,570
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
62
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

Python @NCKU CSIE

  1. 1. Python 郭⾄至軒(KuoE0) KuoE0.tw@gmail.com KuoE0.ch @ Programming Language 2013
  2. 2. Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) http://creativecommons.org/licenses/by-sa/3.0/ Latest update: Jan 10, 2014,
  3. 3. What is Python?
  4. 4. What is Python? a programming language
  5. 5. What is Python? easy to Read easy to Write easy to Learn a programming language
  6. 6. Top Language in TIOBE Position May 2013 Position May 2012 Delta in Position Programming Language 1 2 3 4 5 6 7 8 9 10 1 2 4 3 5 6 7 8 9 11 = = ↑ ↓ = = = = = ↑ C Java Objective-C C++ C# PHP Visual Basic Python Perl Ruby http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
  7. 7. Top Languages in Github Javascript 21% Ruby 12% Java 8% Python 8% Shell 8% PHP 7% C 6% C++ 5% Perl 4% Objective-C 3% 0% 5% 10% 15% 20% 25% https://github.com/languages
  8. 8. Top Languages in Github Javascript 21% Ruby 12% Java 8% Python 8% Shell 8% PHP 7% C 6% C++ 5% Perl 4% Objective-C 3% 0% 5% 10% 15% 20% 25% https://github.com/languages
  9. 9. What does the logo mean?
  10. 10. 界 Kingdom 動物界 Animalia ⾨門 Phylum 脊索動物⾨門 Chordata 綱 Class 爬蟲科 Reptilia ⺫⽬目 Order 有鱗⺫⽬目 Squamata 科 Family 蟒科 Pythonidae 屬 Genus 蟒屬 Python
  11. 11. http://wallpapers.free-review.net/15__Tree_python.htm
  12. 12. http://wallpapers.free-review.net/15__Tree_python.htm
  13. 13. More About Python...
  14. 14. More About Python... Interpreted Language Do not need to compile!
  15. 15. Compiled Language compiler execute
  16. 16. Interpreted Language But, interpret in execution time. execute And, it would be slow...
  17. 17. More About Python... Object-Oriented Language Everything in Python is object!
  18. 18. number string list function Object
  19. 19. number string list function Object
  20. 20. overloading inheritance multiple inheritance polymorphism
  21. 21. More About Python... Imperative Programming Generic Programming Functional Programming
  22. 22. Philosophy
  23. 23. Philosophy There should be one— and preferably only one —obvious way to do it.
  24. 24. Philosophy There should be one— and preferably only one —obvious way to do it.
  25. 25. Zen of Python $
  26. 26. Zen of Python $ python -ic “”
  27. 27. Zen of Python $ python -ic “” >>>
  28. 28. Zen of Python $ python -ic “” >>> import this
  29. 29. Zen of Python one There temptation to guess. and refuse In --obviousbe Unless Errors Althoughcasesbetter breakis betternever pass Peters Specialfacebetter may beats ReadabilityPython,tonested. Sparse explicitly silenced. FlatZenshould“”ambiguity,silently. Complexispracticality dense. obvious Simpleshouldofaren'tthanit. enough Explicitisrules. than complex. Beautifulisthisthanthan implicit.the at The importbetterone--docomplicated. only >>>thethe-iccounts.byspecialpurity. to $ pythonofisbetterthanTimugly. that way not preferably be first one There temptation to way In --obvious guess. and preferably Unless casesyou're Errors betternever Dutch.refuse Althoughisrules. may beats breakisfacebetter topass Peters Specialexplicitlythan dense. ReadabilityPython,silenced. Sparseunlessofaren'tnested. obvious FlatZenshouldbeambiguity,silently. Complexisthatbetter thanit. enough Simpleshouldcounts.than implicit.the at Explicitofbetterone-- complex. Beautifulpracticalitydocomplicated. only The importisbetterthanTimugly. >>>thetheisthisthanbyspecialpurity. to not be Now first one is cases than There temptationrules. In --obvious way may and preferably Unless betterguess. beats Errors better never Dutch.refuse Althoughisbetterone-- dense. breakisfacetoyou're pass Peters Specialexplicitly tonested. Readabilitybetterthan complex. Sparseunlessofaren'tthanit. obvious FlatZenshouldbethannever.silently. Complexisthatbetterthan implicit.the Simpleshouldcounts.bydocomplicated. at Explicitofisbettersilenced. enough only Beautifulpracticalityspecialpurity. to ThethetheisPython,thanTimugly. ambiguity, be not Now first one is cases thanmay not preferably There temptationbetterone-- andsilently. In the better way to beats Unless face Errorsunlessofguess. dense. Althoughbetternever Dutch.refuse breakisexplicitly silenced. Specialshould aren'tpassbetter Readabilitytoyou're nested. obvious Sparseshouldcounts. thanit. enough Flat--obviousbethannever.ugly. Complexisthatbetterthan implicit.the at Simplethepracticalitydocomplicated. only Explicitisisbetterthancomplex. than *right* Beautifulisbetterthanspecialpurity. to never ambiguity, be rules. often is now. Now first one is cases thanmay not preferably There temptationbetterone-- andsilently. In the better way to beats Unless face Errorsunlessofguess. dense. Althoughbetternever Dutch.refuse breakisexplicitly silenced. Specialshould aren'tpassbetter Readabilitytoyou're nested. obvious Sparseshouldcounts. thanit. enough Flat--obviousbethannever.ugly. Complexisthatbetterthan implicit.the at Simplethepracticalitydocomplicated. only Explicitisisbetterthancomplex. than *right* Beautifulisbetterthanspecialpurity. to never ambiguity, be rules. often is If now. Now first one is cases thanoften There implementation isbetter temptationrules. may not preferably In the better way to andhard than Unless face ofguess. beats Errorsunlesscounts. Dutch.refuse Althoughbetternever passit. breakisexplicitly silenced. Specialshould aren'tnested. obvious Readabilitytoyou'renever.silently. Sparseshouldbetterthandense. enough at Flat--obviousbethanthan implicit.explain, Complexispracticality complex.to the only Simpletheisbetterthandocomplicated. *right* Explicitisbetterone--specialpurity. to never is that ambiguity, be it's If now. Now first one is bad idea. may isbetter Therea implementation not preferably temptationrules. to andhard than In the better way silenced. Unless faceto guess. beats Errorsunlessofnever Althoughisbetterone-- dense. breakisexplicitly thancomplex.to explain, Specialshould aren'tDutch.refuse the Readabilitybetterthandocomplicated. Sparseshouldcounts. passit. obvious at Flat--obviousyou're nested. enough only Complexisthatbethannever.silently. *right* Simplethepracticalityspecialpurity. to cases ambiguity, be betterthanoften never is it's If now. Now first bad idea. may one is implementation isbetter Therea better way to noteasy temptationrules. silenced. In the faceto guess. andhard than Unlessunlessofnever Errorsshouldcounts. Dutch.refuse explain, Althoughisbetterone-- beats breakisexplicitly thandense. to the Specialshould aren'tpassit. obvious Readabilitybetterthandocomplicated. at Sparsethethatyou're nested. enough only Flat--obviousbethannever.silently. *right* Complexispracticalityspecialpurity. to cases ambiguity, preferably betterthanoften never is be it it's If now. Now is badrules. may first implementation is preferably onemay better thanto noteasy Therea faceidea. silenced. temptationbetterone-- andhard than In the explicitlyidea.beats Unlessunlessofwaythan dense. Errorsshouldcounts. Althoughbetterguess. do betterto explain, breakisshould never Dutch.refuse the Specialisthat aren'tpassit. obvious at Readabilitytoyou're nested. enough only Sparsethepracticalityspecialpurity. *right* Flat--obviousbethannever.silently. to benever ambiguity, be cases is often a good Namespacesaare is often it it's If now.is badrules. may Now --obvious thanto is first implementation not be onemay better way silenced. There faceidea. idea.andeasy than temptationbetterone-- beats In the explicitlythan dense. obvious Unless should guess. do betterto idea Errorsunlessofnever Dutch.preferably Althoughcases aren'tpassit.great explain, breakashouldcounts.honkingrefuse the at Specialisthatyou'renever.hardenough only Readabilitytobeambiguity,silently. *right* Sparsethepracticalityspecialpurity. to-benever one good let's bad good often Namespacesaareof may it it's If now.is implementation is Now --obvious thanto not be first better way silenced. onemay faceidea. those! There explicitlyidea.andeasy than temptationrules.one-- beats obvious In thedo that guess. do betterto idea Unlessunlessofnever Dutch.preferably Errorsshouldcounts.honkingrefuse explain, Althoughcases aren'tpassit.great the at breakathepracticalityspecialpurity. only Specialshouldyou'renever.hardenough *right* Readabilitytobeambiguity,silently. to-benever is more one >>> let's bad areof often Namespacesaidea. may is it it's If now.is implementation not Now --obvious thanto and be first better way silenced. onemay faceto guess.Dutch.preferably There explicitlythose! easy than temptationrules. idea.beats obvious In thedo that neverhonkingrefuse idea Unlessunlessgoodone--do betterto explain, Errorsshouldofaren'tpassit.great the at Althoughcasesyou'renever.hardenough only breakathepracticalityspecialpurity. *right* Specialshouldbeambiguity,silently. to-benever is more one
  30. 30. Current Situation
  31. 31. Current Situation Python 2.x Python 3.x
  32. 32. Current Situation Python 2.x Python 3.x Coexist!
  33. 33. Current Situation Python 2.x Python 3.x Coexist!
  34. 34. Current Situation backwards-incompatible Python 2.x Python 3.x Coexist!
  35. 35. Python 2.x Python 3.x 2.7.x is the latest version under development more 3-party library 2to3.py built-in on many OS more supported unicode the past in someday the future in someday
  36. 36. Python 3 的新特性 http://www.ibm.com/developerworks/cn/linux/l-python3-1/
  37. 37. Python 2.x
  38. 38. Today, Let’s Talk About Python 2.x
  39. 39. Environment
  40. 40. Environment For Unix-like OS User, Python 2.x is Built-in!
  41. 41. Environment For Windows User, Download From http://www.python.org/download/ if you want to launch Python in command line, add the path of Python binary file into PATH variable.
  42. 42. Check Version of Python $
  43. 43. Check Version of Python $ python --version
  44. 44. Check Version of Python $ python --version Python 2.7.5
  45. 45. Check Version of Python $ python --version Python 2.7.5 2.7.5 is released on May 15, 2013
  46. 46. Check Version of Python $
  47. 47. Check Version of Python $ python
  48. 48. Check Version of Python $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
  49. 49. Check Version of Python $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
  50. 50. Interactive Shell $
  51. 51. Interactive Shell $ python
  52. 52. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
  53. 53. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> prompt
  54. 54. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> prompt means that your turn!
  55. 55. Interactive Shell $
  56. 56. Interactive Shell $ python
  57. 57. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>
  58. 58. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3
  59. 59. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3 6 >>>
  60. 60. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3 6 >>> “Hello World”
  61. 61. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3 6 >>> “Hello World” ‘Hello World’ >>>
  62. 62. Interactive Shell $ python Python 2.7.5 (default, May 20 2013, 23:41:46) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> 1 + 2 + 3 6 >>> “Hello World” ‘Hello World’ >>> x = 100
  63. 63. Interactive Shell Python 2.7.5 (default, May 20 2013, $ python 23:41:46) Python 2.7.5 (default, May 20 2013, [GCC 4.2.1 23:41:46) Compatible Apple LLVM 4.2 (clang-425.0.28)] on Apple [GCC 4.2.1 Compatibledarwin LLVM 4.2 Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin "license" for more information. Type "help", "copyright", "credits" or >>> 1 + 2 + 3 "license" for more information. 6 >>> 1 + 2 + 3 >>> “Hello World” 6 ‘Hello World’ >>> “Hello World” >>> x ‘Hello=World’ 100 >>> x = 100
  64. 64. Interactive Shell Python 2.7.5 (default, May 20 2013, $ python 23:41:46) Python 2.7.5 (default, May 20 2013, [GCC 4.2.1 23:41:46) Compatible Apple LLVM 4.2 (clang-425.0.28)] on Apple [GCC 4.2.1 Compatibledarwin LLVM 4.2 Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin "license" for more information. Type "help", "copyright", "credits" or >>> 1 + 2 + 3 "license" for more information. 6 >>> 1 + 2 + 3 >>> “Hello World” 6 ‘Hello World’ >>> “Hello World” >>> x ‘Hello=World’ 100 >>> x = 100 y 200
  65. 65. Interactive Shell 23:41:46) Python 2.7.5 (default, May 20 2013, $ python [GCC 4.2.1 23:41:46) Compatible May LLVM 4.2 Python 2.7.5 (default,Apple20 2013, (clang-425.0.28)] on Apple [GCC 4.2.1 23:41:46) Compatibledarwin LLVM 4.2 Type "help", "copyright", "credits" (clang-425.0.28)] on Apple [GCC 4.2.1 Compatibledarwin LLVM 4.2or "license" for more information. Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin >>> "license" for more information. Type1"help",3"copyright", "credits" or + 2 + 6 >>> 1 + 2 + 3 "license" for more information. 6 >>> “Hello+World” 1 + 2 3 ‘Hello World’ >>> “Hello World” 6 ‘Hello=World’ >>> “Hello World” x 100 >>> x ‘Hello=World’ y 200 100 >>> x = 100 y 200
  66. 66. Interactive Shell 23:41:46) Python 2.7.5 (default, May 20 2013, $ python [GCC 4.2.1 23:41:46) Compatible May LLVM 4.2 Python 2.7.5 (default,Apple20 2013, (clang-425.0.28)] on Apple [GCC 4.2.1 23:41:46) Compatibledarwin LLVM 4.2 Type "help", "copyright", "credits" (clang-425.0.28)] on Apple [GCC 4.2.1 Compatibledarwin LLVM 4.2or "license" for more information. Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin >>> "license" for more information. Type1"help",3"copyright", "credits" or + 2 + 6 >>> 1 + 2 + 3 "license" for more information. 6 >>> “Hello+World” 1 + 2 3 ‘Hello World’ >>> “Hello World” 6 ‘Hello=World’ >>> “Hello World” x 100 >>> x ‘Hello=World’ y 200 100 >>> x = y y + 100 200
  67. 67. Interactive Shell (clang-425.0.28)] on darwin 23:41:46) Python 2.7.5 (default, May 20 2013, $ python Type "help", "copyright", [GCC 4.2.1 23:41:46) Compatible May"credits" Python 2.7.5 (default,Apple20 2013, or LLVM 4.2 "license" (clang-425.0.28)] information. [GCC 4.2.1 Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 >>> Type "help",3"copyright", "credits" (clang-425.0.28)] on Apple [GCC14.2.1+Compatibledarwin LLVM 4.2or + 2 6 "license" for more information. Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or + 2 ‘Hello 2 + 3 6 >>> 1 +World’ "license" for more information. 6 >>> “Hello+World” x + 2 1 = 100 3 ‘Hello=World’ >>> “Hello World” 6 y 200 ‘Hello=World’ >>> “Hello World” x + y 100 300 y >>> x ‘Hello=World’ 200 100 >>> x = y y + 100 200
  68. 68. Interactive Shell (clang-425.0.28)] on darwin 23:41:46) Python 2.7.5 (default, May 20 2013, $ python Type "help", "copyright", [GCC 4.2.1 23:41:46) Compatible May"credits" Python 2.7.5 (default,Apple20 2013, or LLVM 4.2 "license" (clang-425.0.28)] information. [GCC 4.2.1 Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 >>> Type "help",3"copyright", "credits" (clang-425.0.28)] on Apple [GCC14.2.1+Compatibledarwin LLVM 4.2or + 2 6 "license" for more information. Type "help", "copyright", "credits" or (clang-425.0.28)] on darwin >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or + 2 ‘Hello 2 + 3 6 >>> 1 +World’ "license" for more information. 6 >>> “Hello+World” x + 2 1 = 100 3 ‘Hello=World’ >>> “Hello World” 6 y 200 ‘Hello=World’ >>> “Hello World” x + y 100 300 y >>> x ‘Hello=World’ 200 100 >>> for y in range(5): y + 100 x = i 200
  69. 69. Interactive Shell Type "help", "copyright", (clang-425.0.28)] on darwin20 2013, 23:41:46) Python 2.7.5 (default, May"credits" or $ python "license" Type "help", more information. [GCC 4.2.1 Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python 2.7.5 (default,Apple20 2013, or >>> "license" (clang-425.0.28)] information. [GCC14.2.1+Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 + 2 3 6 >>> Type "help",3"copyright", "credits" (clang-425.0.28)] on Apple [GCC14.2.1+Compatibledarwin LLVM 4.2or + 2 >>> "help", more 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin ‘Hello+World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or 2 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. x 2 + 6 >>> “Hello+World” y x + 200 1 = 100 3 2 ‘Hello=World’ >>> “Hello World” 6 x y + y 200 300 x + y ‘Hello=World’ >>> “Hello World” 100 300 x >>> for i in ‘Hello=World’range(5): y 200 100 ... x = i >>> for y in range(5): y + 100 200
  70. 70. Interactive Shell Type "help", "copyright", (clang-425.0.28)] on darwin20 2013, 23:41:46) Python 2.7.5 (default, May"credits" or $ python "license" Type "help", more information. [GCC 4.2.1 Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python 2.7.5 (default,Apple20 2013, or >>> "license" (clang-425.0.28)] information. [GCC14.2.1+Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 + 2 3 6 >>> Type "help",3"copyright", "credits" (clang-425.0.28)] on Apple [GCC14.2.1+Compatibledarwin LLVM 4.2or + 2 >>> "help", more 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin ‘Hello+World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or 2 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. x 2 + 6 >>> “Hello+World” y x + 200 1 = 100 3 2 ‘Hello=World’ >>> “Hello World” 6 x y + y 200 300 x + y ‘Hello=World’ >>> “Hello World” 100 300 x >>> for i in ‘Hello=World’range(5): y 200 100 ... x = y in i >>> for printrange(5): y + i 200 100
  71. 71. Interactive Shell "license" Type "help", more information. (clang-425.0.28)] on darwin 23:41:46) Python 2.7.5 "copyright", 20 2013, $ python for(default, May"credits" or >>> "license" Type "help", more information. [GCC14.2.1+Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python+2.7.53(default,Apple20 2013, or 2 6 >>> "license" (clang-425.0.28)] information. [GCC14.2.1+Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 + 2 3 6 >>> "help",3"copyright", "credits" Type14.2.1 Compatible Apple (clang-425.0.28)] [GCC“Hello+World” on darwin LLVM 4.2or + 2 ‘Hello World’ >>> "help", more 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin ‘Hello=World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or x + 100 2 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. y x 200 2 + 6 >>> “Hello+World” y x + 100 3 1 = y 200 2 300 y + y ‘Hello=World’ >>> “Hello World” 6 x 200 300 for y World” ‘Hello=World’ >>> “Helloin range(5): x + i 100 ... y 300 x >>> for print i ‘Hello=World’range(5): i in 200 100 ... x = y in i >>> for printrange(5): y + i 200 100
  72. 72. Interactive Shell >>> "license" Typey"help", (clang-425.0.28)] information. 23:41:46) for moreon darwin Python=2.7.5 "copyright", 20 2013, $ python200 (default, May"credits" or >>> "license" Typex"help", more information. [GCC14.2.1+Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python+2.7.53(default,Apple20 2013, or y 2 300 6 >>> "license" (clang-425.0.28)] information. [GCC14.2.1+Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 + 2 3 6 >>> 14.2.1 Compatible Typefor i +World” (clang-425.0.28)] on darwin [GCC“Helloin3range(5):Apple LLVM 4.2or "help", "copyright", "credits" + 2 ... ‘Hello World’ more >>> "help", i 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin print ... x + 100 ‘Hello=World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or 2 0 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. y x 200 2 + 1 6 >>> “Hello+World” y x + 100 3 1 = y 200 2 2 300 y + y ‘Hello=World’ >>> “Hello World” 6 x 200 3 300 for y World” ‘Hello=World’ >>> “Helloin range(5): x + i 100 4 ... y 300 x >>> for print i ‘Hello=World’range(5): i in 200 100 ... x = y in i >>> for printrange(5): y + i 200 100
  73. 73. Interactive Shell >>> "license" Typey"help", (clang-425.0.28)] information. 23:41:46) for moreon darwin Python=2.7.5 "copyright", 20 2013, $ python200 (default, May"credits" or >>> "license" Typex"help", more information. [GCC14.2.1+Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python+2.7.53(default,Apple20 2013, or y 2 300 6 >>> "license" (clang-425.0.28)] information. [GCC14.2.1+Compatible Apple 23:41:46) for moreon darwin LLVM 4.2 + 2 3 6 >>> 14.2.1 Compatible Typefor i +World” (clang-425.0.28)] on darwin [GCC“Helloin3range(5):Apple LLVM 4.2or "help", "copyright", "credits" + 2 ... ‘Hello World’ more >>> "help", i 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin print ... x + 100 ‘Hello=World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or 2 0 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. y x 200 2 + 1 6 >>> “Hello+World” y x + 100 3 1 = y 200 2 2 300 y + y ‘Hello=World’ >>> “Hello World” 6 x 200 3 300 for y World” ‘Hello=World’ >>> “Helloin range(5): x + i 100 4 ... y 300 x >>> for print i ‘Hello=World’range(5): i in 200 100 ... x = y in i >>> for printrange(5): exit() y + i 200 100
  74. 74. Interactive Shell >>> x + 200 "license" Typey"help", more information. (clang-425.0.28)] on darwin 23:41:46) Python=2.7.5 "copyright", 20 2013, $ pythony for(default, May"credits" or 300 >>> "license" Typex"help", more information. [GCC14.2.1+Compatible May LLVM 4.2 23:41:46) for"copyright", "credits" Python+2.7.53(default,Apple20 2013, or y 2 300 6 >>> 14.2.1 "license" +Compatible (clang-425.0.28)] information. [GCCfor i for moreon darwin 23:41:46) in3range(5):Apple LLVM 4.2 + 2 ... "help", i 6 >>> 14.2.1+World” Typefor print"copyright", "credits" (clang-425.0.28)] on darwin [GCC“Helloin3range(5):Apple LLVM 4.2or + i Compatible 2 ... ‘Hello World’ more >>> "help", i 6 "license" World” information. Type“Hellofor"copyright", "credits" or (clang-425.0.28)] on darwin print 0 ... x + 100 ‘Hello=World’ >>> 1"help",3 more "license" +World” information. Type“Hellofor"copyright", "credits" or 2 1 0 ‘Hello+ 100 3 6 >>> 1 =World’ "license" for more information. y x 200 2 + 2 1 6 >>> “Hello+World” y x + 100 3 1 = y 200 2 3 2 300 y + y ‘Hello=World’ >>> “Hello World” 6 x 200 4 3 300 for y World” ‘Hello=World’ >>> “Helloin range(5): x + i 100 4 ... y 300 x >>> for print i ‘Hello=World’range(5): exit()in i 200 100 $ ... x = y in i >>> for printrange(5): exit() y + i 200 100
  75. 75. Hello World!
  76. 76. Hello World! if __name__ == “__main__”: print “Hello World!” helloworld.py
  77. 77. Hello World! $
  78. 78. Hello World! $ python helloworld.py
  79. 79. Hello World! $ python helloworld.py Hello World! $
  80. 80. A Python Code
  81. 81. A Python Code def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) 9x9table.py
  82. 82. script language def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) no specified entry point
  83. 83. script language $
  84. 84. script language $ python 9x9table.py
  85. 85. script language 8 7 6 5 4 3 2 $ 8 7 6 5 4 3 2 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 2 9 8 7 6 5 4 3 9 8 7 6 5 4 3 $ 9 8 7 6 5 4 3 x 1 = 4 python29x9table.py 9 8 7 6 5 4 3 2 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 27 24 21 15 9 3 18 16 14 12 10 8 6 x 1 = 2 9 8 7 6 5 4 3 2 64 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 27 24 21 15 9 3 18 16 14 12 10 8 6 4 x 2 = 4 1 9 8 7 6 5 4 3 72 64 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 27 24 21 15 9 3 18 16 14 12 10 8 6 x 3 = 6 2 1 9 8 7 6 5 4 72 64 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 4 27 24 21 15 9 3 18 16 14 12 10 8 x 4 = 8 3 2 1 9 8 7 6 5 72 64 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 4 27 24 21 15 9 6 3 18 16 14 12 10 x 5 = 10 4 3 2 1 9 8 7 6 72 64 63 56 49 7 54 48 42 45 40 35 30 25 5 36 32 28 20 8 4 27 24 21 15 9 6 3 18 16 14 12 x 6 = 12 5 4 3 2 1 9 8 7 72 64 63 56 49 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 8 4 27 24 21 15 9 6 3 18 16 14 x 7 = 14 6 5 4 3 2 1 9 8 72 64 63 56 49 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 8 4 27 24 21 15 12 9 6 3 18 16 x 8 = 16 7 6 5 4 3 2 1 9 72 64 63 56 49 14 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 8 4 27 24 21 15 12 9 6 3 18 x 9 = 18 8 7 6 5 4 3 2 1 72 64 63 56 49 14 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 16 8 4 27 24 21 15 12 9 6 3 x 1 = 3 9 8 7 6 5 4 3 2 72 64 63 56 49 14 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 16 8 4 27 24 21 18 15 12 9 6 x 2 = 6 1 9 8 7 6 5 4 3 81 72 64 63 56 49 14 7 54 48 42 45 40 35 30 25 10 5 36 32 28 20 16 8 4 27 24 21 18 15 12 9 x 3 = 9 2 1 9 8 7 6 5 4 81 72 64 63 56 49 14 7 54 48 42 6 45 40 35 30 25 10 5 36 32 28 20 16 8 4 27 24 21 18 15 12
  86. 86. If you need a main function as entry point, if __name__ == “__main__”: print “Hello World!”
  87. 87. If you need a main function as entry point, if __name__ == “__main__”: print “Hello World!”
  88. 88. If you need a main function as entry point, if __name__ == “__main__”: print “Hello World!” and write all statements after it.
  89. 89. variable def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) can be used without declaration
  90. 90. variable def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) can be used without declaration
  91. 91. scope def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) use whitespace to identify scope
  92. 92. scope def mul(x, y): ret = x * y return ret for i in range(10)[2:]: for j in range(10)[1:]: print "{0} x {1} = {2}".format(i, j, mul(i, j)) use whitespace to identify scope
  93. 93. You can use to identify scopes.
  94. 94. You can use one space two spaces three spaces four spaces lots of spaces to identify scopes.
  95. 95. You can use one space one tab two spaces two tabs three spaces three tabs four spaces four tabs lots of spaces lots of tabs to identify scopes.
  96. 96. But, you should unify the style!
  97. 97. Built-in Data Type
  98. 98. Null >>> None
  99. 99. Null >>> None None
  100. 100. Null None >>> None >>>
  101. 101. Boolean >>> True False
  102. 102. Boolean >>> 1 == 1 True False
  103. 103. Boolean True False >>> 1 == 1 True >>>
  104. 104. Boolean True False >>> 1 == 1 True >>> 1 != 1
  105. 105. Boolean True False >>> 1 == 1 True >>> 1 != 1 False >>>
  106. 106. Boolean True False >>> 1 == 1 True >>> 1 != 1 False >>> True
  107. 107. Boolean True False >>> 1 == 1 True >>> 1 != 1 False >>> True True >>>
  108. 108. Boolean True False >>> 1 == 1 True >>> 1 != 1 False >>> True True >>> False
  109. 109. Boolean True False True >>> 1 == 1 >>> True1 != 1 False >>> 1 != 1 >>> True False True >>> True >>> TrueFalse False >>> False >>>
  110. 110. Boolean >>> True False
  111. 111. Boolean upper case >>> True False
  112. 112. Boolean upper case >>> true True False
  113. 113. Boolean upper case True False >>> true Traceback (most recent call last): File "<input>", line 1, in <module> NameError: name 'true' is not defined >>>
  114. 114. Initialization / Conversion >>> True False
  115. 115. Initialization / Conversion >>> bool(1) True False
  116. 116. Initialization / Conversion True False >>> bool(1) True >>>
  117. 117. Initialization / Conversion True False >>> bool(1) True >>> bool(True)
  118. 118. Initialization / Conversion True False >>> bool(1) True >>> bool(True) True >>>
  119. 119. Initialization / Conversion True False >>> bool(1) True >>> bool(True) True >>> bool()
  120. 120. Initialization / Conversion True False >>> bool(1) True >>> bool(True) True >>> bool() False >>>
  121. 121. Logical Operators >>> and and or or not not
  122. 122. Logical Operators >>> (1 == 1) and True and and or or not not
  123. 123. Logical Operators and and or or not not >>> (1 == 1) and True True >>>
  124. 124. Logical Operators and and or or not not >>> (1 == 1) and True True >>> (1 == 1) or False
  125. 125. Logical Operators and and or or not not >>> (1 == 1) and True True >>> (1 == 1) or False True >>>
  126. 126. Logical Operators and and or or not not >>> (1 == 1) and True True >>> (1 == 1) or False True >>> not (1 == 1)
  127. 127. Logical Operators and and or or not not >>> (1 == 1) and True True >>> (1 == 1) or False True >>> not (1 == 1) False >>>
  128. 128. Numbers int (integer) long (long integer) float (real number) complex (complex number) 10 10L 100.0 3 + 2j -789 -789L -21.9 3 - 2j -0x111 0xFFFFFFFFF 3.20E+10 45j 0x69 -0x12321L -2.00E-08 3e+26j
  129. 129. Initialization / Conversion data type initial >>> int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  130. 130. Initialization / Conversion data type initial >>> int(10) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  131. 131. Initialization / Conversion data type initial >>> int(10) 10 >>> int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  132. 132. Initialization / Conversion data type initial >>> int(10) 10 >>> int(“100”) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  133. 133. Initialization / Conversion data type initial >>> int(10) 10 >>> int(“100”) 100 >>> int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  134. 134. Initialization / Conversion data type initial >>> int(10) 10 >>> int(“100”) 100 >>> complex(10) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  135. 135. Initialization / Conversion data type initial >>> int(10) 10 >>> int(“100”) 100 >>> complex(10) (10+0j) >>> int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  136. 136. Initialization / Conversion data type initial >>> int(10) 10 >>> int(“100”) 100 >>> complex(10) (10+0j) >>> complex(10, 3) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  137. 137. Initialization / Conversion data type initial 10 >>> int(10) >>> 10 int(“100”) 100 >>> int(“100”) >>> 100 complex(10) (10+0j) >>> complex(10) >>> complex(10, 3) (10+0j) (10+3j) >>> complex(10, 3) >>> int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  138. 138. Initialization / Conversion data type initial 10 >>> int(10) >>> 10 int(“100”) 100 >>> int(“100”) >>> 100 complex(10) (10+0j) >>> complex(10) >>> complex(10, 3) (10+0j) (10+3j) >>> complex(10, 3) >>> complex(“20+5j”) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  139. 139. Initialization / Conversion data type initial 100 10 >>> int(10) >>> complex(10) 10 int(“100”) (10+0j) 100 >>> int(“100”) >>> complex(10, 100 complex(10) 3) (10+3j) (10+0j) >>> complex(10) >>> complex(10, 3) (10+0j) complex(“20+5j”) (20+5j) (10+3j) >>> complex(10, 3) >>> complex(“20+5j”) int int(x) long long(x) float float(x) complex complex(x) complex(x, y)
  140. 140. Arithmetic Operators + addition - subtraction * multiplication / division % modular ** exponential // floor division >>>
  141. 141. Arithmetic Operators + addition - subtraction * multiplication / division % modular ** exponential // floor division >>> 2**10
  142. 142. Arithmetic Operators + addition - subtraction * multiplication / division % modular ** exponential // floor division >>> 2**10 1024 >>>
  143. 143. Arithmetic Operators + addition - subtraction * multiplication / division % modular ** exponential // floor division >>> 2**10 1024 >>> 5.8 // 2
  144. 144. Arithmetic Operators + addition - subtraction * multiplication / division % modular ** exponential // floor division >>> 2**10 1024 >>> 5.8 // 2 2.0 >>>
  145. 145. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>>
  146. 146. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1
  147. 147. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1 1 >>>
  148. 148. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1 1 >>> 1 << 10
  149. 149. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1 1 >>> 1 << 10 1024 >>>
  150. 150. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1 1 >>> 1 << 10 1024 >>> ~0
  151. 151. Bitwise Operators & and | or ^ exclusion or >> shift right << shift left ~ not >>> 3 & 1 1 >>> 1 << 10 1024 >>> ~0 -1 >>>
  152. 152. Comparison Operators > >= < <= == != greater than greater than or equal to less than less than or equal to equal to not equal to
  153. 153. String Contents are surrounded by single quote or double quote. >>>
  154. 154. String Contents are surrounded by single quote or double quote. >>> “Hello World”
  155. 155. String Contents are surrounded by single quote or double quote. >>> “Hello World” ‘Hello World’ >>>
  156. 156. String Contents are surrounded by single quote or double quote. >>> “Hello World” World!” ‘Hello World’ >>> ‘Hello World!’
  157. 157. String Contents are surrounded by single quote or double quote. >>> “Hello World” World!” ‘Hello World’ >>> ‘Hello World!’ ‘Hello World’ >>>
  158. 158. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>>
  159. 159. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello
  160. 160. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ...
  161. 161. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!”””
  162. 162. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>>
  163. 163. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>> x = “““Hello
  164. 164. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>> x = “““Hello ...
  165. 165. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>> x = “““Hello ... World!”””
  166. 166. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>> x = “““Hello ... World!””” >>>
  167. 167. Cross-line String Contents are surrounded by three single quotes or three double quotes. >>> “““Hello ... World!””” ‘HellonWorld!’ >>> x = “““Hello ... World!””” >>> print x
  168. 168. Cross-line String Contents are surrounded by three single quotes or three double quotes. ... World!””” >>> “““Hello ‘HellonWorld!’ ... World!””” >>> x = “““Hello ‘HellonWorld!’ ... x = “““Hello >>> World!””” >>> print x ... World!””” Hello >>> print x World! >>>
  169. 169. Initialization / Conversion >>>
  170. 170. Initialization / Conversion >>> str(“I’m string”)
  171. 171. Initialization / Conversion >>> str(“I’m string”) “I’m string” >>>
  172. 172. Initialization / Conversion >>> str(“I’m string”) “I’m string” >>> str(100)
  173. 173. Initialization / Conversion >>> str(“I’m string”) “I’m string” >>> str(100) ‘100’ >>>
  174. 174. Initialization / Conversion >>> str(“I’m string”) “I’m string” >>> str(100) ‘100’ >>> str(complex(10, 3))
  175. 175. Initialization / Conversion >>> str(“I’m string”) “I’m string” >>> str(100) ‘100’ >>> str(complex(10, 3)) ‘(10+3j)’ >>>
  176. 176. Operators >>> + concatenate * repeat
  177. 177. Operators >>> x = “abc” + concatenate * repeat
  178. 178. Operators >>> x = “abc” >>> + concatenate * repeat
  179. 179. Operators >>> x = “abc” >>> ‘(’ + x + ‘)’ + concatenate * repeat
  180. 180. Operators + concatenate * repeat >>> x = “abc” >>> ‘(’ + x + ‘)’ ‘(abc)’ >>>
  181. 181. Operators + concatenate * repeat >>> x = “abc” >>> ‘(’ + x + ‘)’ ‘(abc)’ >>> x * 3
  182. 182. Operators + concatenate * repeat >>> x = “abc” >>> ‘(’ + x + ‘)’ ‘(abc)’ >>> x * 3 ‘abcabcabc’ >>>
  183. 183. Operators + concatenate * repeat >>> x = “abc” >>> ‘(’ + x + ‘)’ ‘(abc)’ >>> x * 3 ‘abcabcabc’ >>> ‘(’ + x * 3 + ‘)’
  184. 184. Operators + concatenate * repeat >>> x = “abc” ‘abc’ >>> ‘(’ + x + ‘)’ ‘(abc)’ >>> x * 3 ‘abcabcabc’ >>> ‘(’ + x * 3 + ‘)’ ‘(abcabcabc)’ >>>
  185. 185. Operators + concatenate * repeat >>> x = “abc” ‘abc’ >>> ‘(’ + x + ‘)’ ‘(abc)’ >>> x * 3 ‘abcabcabc’ >>> ‘(’ + x * 3 + ‘)’ ‘(abcabcabc)’ >>> (x + ‘d’) * 3
  186. 186. Operators + concatenate * repeat ‘(abc)’ ‘abc’ >>> x = “abc” >>> ‘(’ + x + ‘)’ x * 3 ‘abcabcabc’ ‘(abc)’ >>> ‘(’ + x * 3 + ‘)’ x * 3 ‘(abcabcabc)’ ‘abcabcabc’ >>> ‘(’++‘d’) * 3 ‘)’ (x x * 3 + ‘abcdabcdabcd’ ‘(abcabcabc)’ >>> (x + ‘d’) * 3
  187. 187. Access Character >>>
  188. 188. Access Character >>> x = ‘0123456789’
  189. 189. Access Character >>> x = ‘0123456789’ >>>
  190. 190. Access Character >>> x = ‘0123456789’ >>> x[1]
  191. 191. Access Character >>> x = ‘0123456789’ >>> x[1] ‘1’ >>>
  192. 192. Access Character >>> x = ‘0123456789’ >>> x[1] ‘1’ >>> x[1] = ‘0’
  193. 193. Access Character >>> x = ‘0123456789’ >>> x[1] ‘1’ >>> x[1] = ‘0’ >>>
  194. 194. Access Character >>> >>> ‘1’ >>> >>> x = ‘0123456789’ x[1] x[1] = ‘0’ x
  195. 195. Access Character >>> x = ‘0123456789’ >>> x[1] ‘1’ >>> x[1] = ‘0’ >>> x ‘0023456789’ >>>
  196. 196. substring >>> [start:end(:step)]
  197. 197. substring >>> [start:end(:step)] default value [0:length(:1)]
  198. 198. substring >>> x = “0123456789” [start:end(:step)] default value [0:length(:1)]
  199. 199. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>>
  200. 200. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::]
  201. 201. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>>
  202. 202. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>> x[:]
  203. 203. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>> x[:] ‘0123456789’ >>>
  204. 204. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>> x[:] ‘0123456789’ >>> x[1:4]
  205. 205. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>> x[:] ‘0123456789’ >>> x[1:4] ‘123’ >>>
  206. 206. substring [start:end(:step)] default value [0:length(:1)] >>> x = “0123456789” >>> x[::] ‘0123456789’ >>> x[:] ‘0123456789’ >>> x[1:4] ‘123’ >>> x[1:-1]
  207. 207. substring [start:end(:step)] default value [0:length(:1)] ‘0123456789’ >>> x = “0123456789” >>> x[::] x[:] ‘0123456789’ >>> x[:] x[1:4] ‘123’ ‘0123456789’ >>> x[1:4] x[1:-1] ‘12345678’ ‘123’ >>> x[1:-1]
  208. 208. substring [start:end(:step)] default value [0:length(:1)] ‘0123456789’ >>> x = “0123456789” >>> x[::] x[:] ‘0123456789’ >>> x[:] x[1:4] ‘123’ ‘0123456789’ >>> x[1:4] x[1:-1] ‘12345678’ ‘123’ >>> x[1:-1] x[::2]
  209. 209. substring [start:end(:step)] default value [0:length(:1)] ‘0123456789’ >>> x = “0123456789” >>> x[::] x[1:4] x[:] ‘123’ ‘0123456789’ >>> x[:] x[1:-1] x[1:4] ‘12345678’ ‘123’ ‘0123456789’ >>> x[1:4] x[::2] x[1:-1] ‘02468’ ‘12345678’ ‘123’ >>> x[1:-1] x[::2]
  210. 210. substring [start:end(:step)] default value [0:length(:1)] ‘0123456789’ >>> x = “0123456789” >>> x[::] x[1:4] x[:] ‘123’ ‘0123456789’ >>> x[:] x[1:-1] x[1:4] ‘12345678’ ‘123’ ‘0123456789’ >>> x[1:4] x[::2] x[1:-1] ‘02468’ ‘12345678’ ‘123’ >>> x[1:-1] x[::-1] x[::2]
  211. 211. substring [start:end(:step)] default value [0:length(:1)] ‘123’ ‘0123456789’ >>> x = “0123456789” >>> x[::] x[1:-1] x[1:4] x[:] ‘12345678’ ‘123’ ‘0123456789’ >>> x[:] x[::2] x[1:-1] x[1:4] ‘02468’ ‘12345678’ ‘123’ ‘0123456789’ >>> x[1:4] x[::-1] x[::2] x[1:-1] ‘9876543210’ ‘02468’ ‘12345678’ ‘123’ >>> x[1:-1] x[::-1] x[::2]
  212. 212. length of string >>> len(string)
  213. 213. length of string >>> x = ‘0123456789’ len(string)
  214. 214. length of string len(string) >>> x = ‘0123456789’ >>>
  215. 215. length of string len(string) >>> x = ‘0123456789’ >>> len(x)
  216. 216. length of string len(string) >>> x = ‘0123456789’ >>> len(x) 10 >>>
  217. 217. length of string len(string) >>> x = ‘0123456789’ >>> len(x) 10 >>> len(x[::2])
  218. 218. length of string len(string) >>> x = ‘0123456789’ >>> len(x) 10 >>> len(x[::2]) 5 >>>
  219. 219. List Contents are surrounded by square brackets and separate by comma. >>>
  220. 220. List Contents are surrounded by square brackets and separate by comma. >>> [“aaa”, “bbb”, 1, 2]
  221. 221. List Contents are surrounded by square brackets and separate by comma. >>> [“aaa”, “bbb”, 1, 2] [‘aaa’, ‘bbb’, 1, 2] >>>
  222. 222. Initialization / Conversion >>>
  223. 223. Initialization / Conversion >>> list([1, 2, 3])
  224. 224. Initialization / Conversion >>> list([1, 2, 3]) [1, 2, 3] >>>
  225. 225. Initialization / Conversion >>> list([1, 2, 3]) [1, 2, 3] >>> list(“abc”)
  226. 226. Initialization / Conversion >>> list([1, 2, 3]) [1, 2, 3] >>> list(“abc”) [‘a’, ‘b’, ‘c’] >>>
  227. 227. Operators >>> + append * repeat
  228. 228. Operators >>> x = [1, 2, 3] + append * repeat
  229. 229. Operators >>> x = [1, 2, 3] >>> + append * repeat
  230. 230. Operators >>> x = [1, 2, 3] >>> y = [‘a’, ‘b’] + append * repeat
  231. 231. Operators + append * repeat >>> x = [1, 2, 3] >>> y = [‘a’, ‘b’] >>>
  232. 232. Operators + append * repeat >>> x = [1, 2, 3] >>> y = [‘a’, ‘b’] >>> x * 2
  233. 233. Operators + append * repeat >>> >>> >>> [1, >>> x = [1, 2, 3] y = [‘a’, ‘b’] x * 2 2, 3, 1, 2, 3]
  234. 234. Operators + append * repeat >>> >>> >>> [1, >>> x = [1, 2, 3] y = [‘a’, ‘b’] x * 2 2, 3, 1, 2, 3] x + y
  235. 235. Operators + append * repeat >>> >>> >>> [1, >>> [1, >>> x = [1, 2, 3] y = [‘a’, ‘b’] x * 2 2, 3, 1, 2, 3] x + y 2, 3, ‘a’, ‘b’]
  236. 236. Access Element >>>
  237. 237. Access Element >>> x = [1, 2, 3, 4, 5]
  238. 238. Access Element >>> x = [1, 2, 3, 4, 5] >>>
  239. 239. Access Element >>> x = [1, 2, 3, 4, 5] >>> x[1]
  240. 240. Access Element >>> x = [1, 2, 3, 4, 5] >>> x[1] 2 >>>
  241. 241. Access Element >>> x = [1, 2, 3, 4, 5] >>> x[1] 2 >>> x[1] = ‘0’
  242. 242. Access Element >>> x = [1, 2, 3, 4, 5] >>> x[1] 2 >>> x[1] = ‘0’ >>>
  243. 243. Access Element >>> >>> 2 >>> >>> x = [1, 2, 3, 4, 5] x[1] x[1] = ‘0’ x
  244. 244. Access Element >>> >>> 2 >>> >>> [1, >>> x = [1, 2, 3, 4, 5] x[1] x[1] = ‘0’ x ‘0’, 3, 4, 5]
  245. 245. Slice >>> [start:end(:step)]
  246. 246. Slice >>> [start:end(:step)] default value [0:length(:1)]
  247. 247. Slice >>> x = [1, 2, 3, 4, 5] [start:end(:step)] default value [0:length(:1)]
  248. 248. Slice [start:end(:step)] default value [0:length(:1)] >>> x = [1, 2, 3, 4, 5] >>>
  249. 249. Slice [start:end(:step)] default value [0:length(:1)] >>> x = [1, 2, 3, 4, 5] >>> x[::]
  250. 250. Slice [start:end(:step)] default value [0:length(:1)] >>> x = [1, 2, 3, 4, 5] >>> x[::] [1, 2, 3, 4, 5] >>>
  251. 251. Slice [start:end(:step)] default value [0:length(:1)] >>> >>> [1, >>> x = [1, 2, 3, 4, 5] x[::] 2, 3, 4, 5] x[:]
  252. 252. Slice [start:end(:step)] default value [0:length(:1)] >>> >>> [1, >>> [1, >>> x = [1, 2, 3, 4, 5] x[::] 2, 3, 4, 5] x[:] 2, 3, 4, 5]
  253. 253. Slice [start:end(:step)] default value [0:length(:1)] >>> >>> [1, >>> [1, >>> x = [1, 2, 3, 4, 5] x[::] 2, 3, 4, 5] x[:] 2, 3, 4, 5] x[1:3]
  254. 254. Slice [start:end(:step)] default value [0:length(:1)] >>> >>> [1, >>> [1, >>> [2, >>> x = [1, 2, 3, 4, 5] x[::] 2, 3, 4, 5] x[:] 2, 3, 4, 5] x[1:3] 3]
  255. 255. Slice [start:end(:step)] default value [0:length(:1)] >>> >>> [1, >>> [1, >>> [2, >>> x = [1, 2, 3, 4, 5] x[::] 2, 3, 4, 5] x[:] 2, 3, 4, 5] x[1:3] 3] x[1:-1]
  256. 256. Slice [start:end(:step)] default value [0:length(:1)] [1, >>> >>> [1, >>> [2, [1, >>> [2, >>> 2, [1, 5] x =3, 4,2, 3, 4, 5] x[:] x[::] 2, 3, 4, 5] x[1:3] x[:] 3] 2, 3, 4, 5] x[1:-1] x[1:3] 3, 3] 4] x[1:-1]
  257. 257. Slice [start:end(:step)] default value [0:length(:1)] [1, >>> >>> [1, >>> [2, [1, >>> [2, >>> 2, [1, 5] x =3, 4,2, 3, 4, 5] x[:] x[::] 2, 3, 4, 5] x[1:3] x[:] 3] 2, 3, 4, 5] x[1:-1] x[1:3] 3, 3] 4] x[::2] x[1:-1]
  258. 258. Slice [start:end(:step)] default value [0:length(:1)] [1, >>> >>> [2, [1, >>> [2, [1, >>> [1, [2, >>> 2, [1, 5] x =3, 4,2, 3, 4, 5] x[1:3] x[:] x[::] 3] 2, 3, 4, 5] x[1:-1] x[1:3] x[:] 3, 3] 4] 2, 3, 4, 5] x[::2] x[1:-1] x[1:3] 3, 5] 3] 4] x[::2] x[1:-1]
  259. 259. Slice [start:end(:step)] default value [0:length(:1)] [1, >>> >>> [2, [1, >>> [2, [1, >>> [1, [2, >>> 2, [1, 5] x =3, 4,2, 3, 4, 5] x[1:3] x[:] x[::] 3] 2, 3, 4, 5] x[1:-1] x[1:3] x[:] 3, 3] 4] 2, 3, 4, 5] x[::2] x[1:-1] x[1:3] 3, 5] 3] 4] x[::-1] x[::2] x[1:-1]
  260. 260. Slice [start:end(:step)] default value [0:length(:1)] [2, [1, >>> >>> [2, [1, >>> [2, [1, >>> [5, [1, [2, >>> 3] 2, [1, 5] x =3, 4,2, 3, 4, 5] x[1:-1] x[1:3] x[:] x[::] 3, 3] 4] 2, 3, 4, 5] x[::2] x[1:-1] x[1:3] x[:] 3, 5] 3] 4] 2, 3, 4, 5] x[::-1] x[::2] x[1:-1] x[1:3] 4, 3, 3, 5] 3] 4] 2, 1] x[::-1] x[::2] x[1:-1]
  261. 261. length of list >>> len(list)
  262. 262. length of list >>> x = [1, 2, 3, 4, 5] len(list)
  263. 263. length of list len(list) >>> x = [1, 2, 3, 4, 5] >>>
  264. 264. length of list len(list) >>> x = [1, 2, 3, 4, 5] >>> len(x)
  265. 265. length of list len(list) >>> x = [1, 2, 3, 4, 5] >>> len(x) 5 >>>
  266. 266. length of list len(list) >>> x = [1, 2, 3, 4, 5] >>> len(x) 5 >>> len(x[::2])
  267. 267. length of list len(list) >>> x = [1, 2, 3, 4, 5] >>> len(x) 5 >>> len(x[::2]) 3 >>>
  268. 268. Tuple >>> Immutable List
  269. 269. Tuple >>> (1, ‘aaa’, 2) Immutable List
  270. 270. Tuple >>> (1, ‘aaa’, 2) (1, ‘aaa’, 2) >>> Immutable List
  271. 271. Tuple >>> (1, ‘aaa’, 2) (1, ‘aaa’, 2) >>> 1, ‘aaa’, 2 Immutable List
  272. 272. Tuple Immutable List >>> (1, >>> (1, >>> (1, ‘aaa’, 2) ‘aaa’, 2) 1, ‘aaa’, 2 ‘aaa’, 2)
  273. 273. Tuple Immutable List >>> (1, >>> (1, >>> (1, ‘aaa’, 2) ‘aaa’, 2) 1, ‘aaa’, 2 ‘aaa’, 2) x = (1, ‘aaa’, 2)
  274. 274. Tuple Immutable List >>> (1, >>> (1, >>> >>> (1, ‘aaa’, 2) ‘aaa’, 2) 1, ‘aaa’, 2 ‘aaa’, 2) x = (1, ‘aaa’, 2)
  275. 275. Tuple Immutable List >>> (1, >>> (1, >>> >>> (1, ‘aaa’, 2) ‘aaa’, 2) 1, ‘aaa’, 2 ‘aaa’, 2) x = (1, ‘aaa’, 2) x[1] = 3
  276. 276. Tuple Immutable List >>> (1, ‘aaa’, 2) x[1] = 3 Traceback 2) (1, ‘aaa’,(most recent call last): >>> 1, ‘aaa’, 2 (1, ‘aaa’, 2) File "<input>", line 1, x <module> >>>in = (1, ‘aaa’, 2) TypeError: 'tuple' >>> x[1] = 3 object does not support item assignment
  277. 277. Tuple Immutable List Traceback=(most recent >>> (1, ‘aaa’, 2) x[1] 3 call last): Traceback 2) (1, ‘aaa’,(most recent call last): >>> 1, ‘aaa’, 2 File "<input>", line 1,File "<input>", line (1,in <module> ‘aaa’, 2) TypeError: ‘aaa’, 1, x <module> >>>in = (1,'tuple' 2) object does TypeError: 'tuple' >>> x[1] = 3not support item assignment object does not support >>> item assignment
  278. 278. Initialization / Conversion >>>
  279. 279. Initialization / Conversion >>> tuple([1, 2, 3])
  280. 280. Initialization / Conversion >>> tuple([1, 2, 3]) (1, 2, 3) >>>
  281. 281. Access Element >>>
  282. 282. Access Element >>> x = (1, 2, 3)
  283. 283. Access Element >>> x = (1, 2, 3) >>>
  284. 284. Access Element >>> x = (1, 2, 3) >>> x[1]
  285. 285. Access Element >>> x = (1, 2, 3) >>> x[1] 2 >>>
  286. 286. Access Element >>> x = (1, 2, 3) >>> x[1] 2 >>> a, b, c = x
  287. 287. Access Element >>> x = (1, 2, 3) >>> x[1] 2 >>> a, b, c = x >>>
  288. 288. Access Element >>> >>> 2 >>> >>> x = (1, 2, 3) x[1] a, b, c = x a
  289. 289. Access Element >>> >>> 2 >>> >>> 1 >>> x = (1, 2, 3) x[1] a, b, c = x a
  290. 290. Access Element >>> >>> 2 >>> >>> 1 >>> x = (1, 2, 3) x[1] a, b, c = x a b
  291. 291. Access Element >>> 2 >>> >>> 2 >>> 1 >>> >>> 1 2 >>> >>> x[1] x = (1, 2, 3) x[1] a, b, c = x a a, b, c = x a b b
  292. 292. Access Element >>> 2 >>> >>> 2 >>> 1 >>> >>> 1 2 >>> >>> x[1] x = (1, 2, 3) x[1] a, b, c = x a a, b, c = x a b b c
  293. 293. Access Element >>> 2 >>> 1 >>> 2 >>> 2 1 >>> >>> 1 3 2 >>> >>> a, x[1](1, = x =b, c 2,x3) a x[1] a, b, c = x b a a, b, c = x a c b b c
  294. 294. length of tuple >>> len(tuple)
  295. 295. length of tuple >>> x = 1, 2, 3, 4, 5 len(tuple)
  296. 296. length of tuple len(tuple) >>> x = 1, 2, 3, 4, 5 >>>
  297. 297. length of tuple len(tuple) >>> x = 1, 2, 3, 4, 5 >>> len(x)
  298. 298. length of tuple len(tuple) >>> x = 1, 2, 3, 4, 5 >>> len(x) 5 >>>
  299. 299. Dictionary key-value relation key value >>>
  300. 300. Dictionary key-value relation key value >>>
  301. 301. Dictionary key-value relation key value >>> x = dict()
  302. 302. Dictionary key-value relation key value >>> x = dict() >>>
  303. 303. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123
  304. 304. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>>
  305. 305. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>> x[111] = ‘aaa’
  306. 306. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>> x[111] = ‘aaa’ >>>
  307. 307. Dictionary key-value relation key value >>> >>> >>> >>> x = dict() x[‘abc’] = 123 x[111] = ‘aaa’ x
  308. 308. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>> x[111] = ‘aaa’ >>> x {‘abc’: 123, 111: ‘aaa’} >>>
  309. 309. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>> x[111] = ‘aaa’ >>> x {‘abc’: 123, 111: ‘aaa’} >>> {1: 20, 2: 30}
  310. 310. Dictionary key-value relation key value >>> x = dict() >>> x[‘abc’] = 123 >>> x[111] = ‘aaa’ >>> x {‘abc’: 123, 111: ‘aaa’} >>> {1: 20, 2: 30} {1: 20, 2: 30} >>>
  311. 311. Initialization / Conversion >>>
  312. 312. Initialization / Conversion >>> dict()
  313. 313. Initialization / Conversion >>> dict() {} >>>
  314. 314. Initialization / Conversion >>> dict() {} >>> dict(one=1, two=2)
  315. 315. Initialization / Conversion >>> dict() {} >>> dict(one=1, two=2) {‘one’: 1, ‘two’: 2} >>>
  316. 316. Initialization / Conversion >>> dict() {} >>> dict(one=1, two=2) {‘one’: 1, ‘two’: 2} >>> dict([('two', 2), (‘one’: 1)])
  317. 317. Initialization / Conversion >>> dict() {} >>> dict(one=1, two=2) {‘one’: 1, ‘two’: 2} >>> dict([('two', 2), (‘one’: 1)]) {‘one’: 1, ‘two’: 2} >>>
  318. 318. Initialization / Conversion {} >>> dict() >>> {} dict(one=1, two=2) {‘one’: 1, ‘two’: 2} >>> dict(one=1, two=2) >>> dict([('two', 2} {‘one’: 1, ‘two’: 2), (‘one’: 1)]) >>> dict([('two', 2), {‘one’: 1, ‘two’: 2} (‘one’: 1)]) >>> dict({‘one’: 2} {‘one’: 1, ‘two’:1, ‘two’: 2}) >>> dict({‘one’: 1,
  319. 319. Initialization / Conversion {‘one’: 1, {} >>> dict() ‘two’: 2} >>> dict([('two', 2), {} dict(one=1, two=2) (‘one’: 1, ‘two’: 2} {‘one’: 1)]) >>> dict(one=1, two=2) >>> dict([('two', 2} {‘one’: 1, ‘two’: 2), (‘one’: 1)]) >>> dict([('two',1, dict({‘one’: 2), ‘two’: 1, {‘one’: 1)]) (‘one’:2}) ‘two’: 2} >>> dict({‘one’: 2} {‘one’: 1, ‘two’:1, ‘two’: 2}) >>> dict({‘one’: 1,
  320. 320. number of dictionary >>> len(dict)
  321. 321. number of dictionary len(dict) >>> x = {‘one’: 1, ‘two’: 2}
  322. 322. number of dictionary len(dict) >>> x = {‘one’: 1, ‘two’: 2} >>>
  323. 323. number of dictionary len(dict) >>> x = {‘one’: 1, ‘two’: 2} >>> len(x)
  324. 324. number of dictionary len(dict) >>> x = {‘one’: 1, ‘two’: 2} >>> len(x) 2 >>>
  325. 325. Control
  326. 326. Condition >>>
  327. 327. Condition >>> x = 100
  328. 328. Condition >>> x = 100 >>>
  329. 329. Condition >>> x = 100 >>> if x > 100:
  330. 330. Condition >>> x = 100 >>> if x > 100: ...
  331. 331. Condition >>> x = 100 >>> if x > 100: ... x = x + 10
  332. 332. Condition >>> x = 100 >>> if x > 100: ... x = x + 10 ...
  333. 333. Condition >>> x = 100 >>> if x > 100: ... x = x + 10 ... elif x < 100:
  334. 334. Condition >>> x = 100 >>> if x > 100: ... x = x + 10 ... elif x < 100: ...
  335. 335. Condition >>> x = 100 >>> if x > 100: ... x = x + 10 ... elif x < 100: ... x = x - 10
  336. 336. Condition >>> x = 100 >>> if x > 100: ... x = x + 10 ... elif x < 100: ... x = x - 10 ...
  337. 337. Condition >>> >>> ... ... ... ... x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else:
  338. 338. Condition >>> >>> ... ... ... ... ... x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else:
  339. 339. Condition >>> >>> ... ... ... ... ... x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0
  340. 340. Condition >>> >>> ... ... ... ... ... ... x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0
  341. 341. Condition >>> >>> ... ... ... ... ... ... >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0
  342. 342. Condition >>> >>> ... ... ... ... ... ... >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0 x
  343. 343. Condition >>> >>> ... ... ... ... ... ... >>> 0 >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0 x
  344. 344. Condition >>> >>> ... ... ... ... ... ... >>> 0 >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0 x
  345. 345. Condition >>> >>> ... ... ... ... ... ... >>> 0 >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0 x else if
  346. 346. Condition >>> >>> ... ... ... ... ... ... >>> 0 >>> x = 100 if x > 100: x = x + 10 elif x < 100: x = x - 10 else: x = 0 no switch statement in Python x else if
  347. 347. Loop >>>
  348. 348. Loop >>> i = 0
  349. 349. Loop >>> i = 0 >>>
  350. 350. Loop >>> i = 0 >>> while i < 3:
  351. 351. Loop >>> i = 0 >>> while i < 3: ...
  352. 352. Loop >>> i = 0 >>> while i < 3: ... i = i + 1
  353. 353. Loop >>> i = 0 >>> while i < 3: ... i = i + 1 ...
  354. 354. Loop >>> i = 0 >>> while i < 3: ... i = i + 1 ... print i
  355. 355. Loop >>> i = 0 >>> while i < 3: ... i = i + 1 ... print i ...
  356. 356. Loop >>> i = 0 >>> while i < 3: ... i = i + 1 ... print i ... 1 2 3 >>>
  357. 357. Loop >>> i = 0 >>> while i < 3: ... i = i + 1 ... print i ... 1 2 3 >>> no do-while statement in Python
  358. 358. Traversal Sequence >>>
  359. 359. Traversal Sequence >>> x = [1, 2, 3, 4, 5]
  360. 360. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>>
  361. 361. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x:
  362. 362. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ...
  363. 363. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ... print i
  364. 364. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ... print i ...
  365. 365. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ... print i ... 1 2 3 4 5 >>>
  366. 366. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ... print i ... 1 2 3 4 5 >>>
  367. 367. Traversal Sequence >>> x = [1, 2, 3, 4, 5] >>> for i in x: ... print i ... 1 2 3 4 5 >>> must be a iterable object
  368. 368. Addition for Loop skip remaining statement and continue continue loop >>>
  369. 369. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5):
  370. 370. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ...
  371. 371. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2:
  372. 372. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2: ...
  373. 373. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2: ... continue
  374. 374. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2: ... continue ...
  375. 375. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2: ... continue ... print i
  376. 376. Addition for Loop skip remaining statement and continue continue loop >>> for i in range(5): ... if i == 2: ... continue ... print i ...
  377. 377. Addition for Loop skip remaining statement and continue continue loop ... >>> for ifin range(5): i i == 2: ... if icontinue == 2: ... print i continue ... print i 0 ... 1 3 4 >>>
  378. 378. Addition for Loop break >>> exit from loop
  379. 379. Addition for Loop break exit from loop >>> for i in range(5):
  380. 380. Addition for Loop break exit from loop >>> for i in range(5): ...
  381. 381. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2:
  382. 382. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ...
  383. 383. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ... break
  384. 384. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ... break ...
  385. 385. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ... break ... print i
  386. 386. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ... break ... print i ...
  387. 387. Addition for Loop break exit from loop >>> for i in range(5): ... if i == 2: ... break ... print i ... 0 1 >>>
  388. 388. Addition for Loop else >>> do something after unbroken loop
  389. 389. Addition for Loop else do something after unbroken loop >>> for i in range(3):
  390. 390. Addition for Loop else do something after unbroken loop >>> for i in range(3): ...
  391. 391. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i
  392. 392. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i ...
  393. 393. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i ... else:
  394. 394. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i ... else: ...
  395. 395. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i ... else: ... print “done”
  396. 396. Addition for Loop else do something after unbroken loop >>> for i in range(3): ... print i ... else: ... print “done” ...
  397. 397. Addition for Loop else do something after unbroken loop ... >>> for i in range(3): print i ... else: print i ... else: print “done” ... print “done” 0 ... 1 2 done >>>
  398. 398. Standard I/O
  399. 399. Evaluated Input input >>> read a string can be evaluated return an evaluated object
  400. 400. Evaluated Input input >>> input() read a string can be evaluated return an evaluated object
  401. 401. Evaluated Input input >>> input() 1 read a string can be evaluated return an evaluated object
  402. 402. Evaluated Input input >>> input() 1 1 >>> read a string can be evaluated return an evaluated object
  403. 403. Evaluated Input input >>> input() 1 1 >>> input() read a string can be evaluated return an evaluated object
  404. 404. Evaluated Input input >>> input() 1 1 >>> input() 1 + 2 read a string can be evaluated return an evaluated object
  405. 405. Evaluated Input input >>> input() 1 1 >>> input() 1 + 2 3 >>> read a string can be evaluated return an evaluated object
  406. 406. Evaluated Input read a string can be evaluated return an evaluated object input >>> 1 1 >>> 1 + 3 >>> input() input() 2 input()
  407. 407. Evaluated Input read a string can be evaluated return an evaluated object input >>> 1 1 >>> 1 + 3 >>> 5.0 input() input() 2 input() / 2
  408. 408. Evaluated Input read a string can be evaluated return an evaluated object input 1 >>> 1 >>> 1 1 + >>> 3 1 + >>> 3 5.0 >>> 2.5 5.0 >>> input() input() 2 input() 2 input() / 2 input() / 2
  409. 409. Evaluated Input read a string can be evaluated return an evaluated object input 1 >>> >>> 1 >>> 1 + 3 1 + >>> >>> 3 1 + 5.0 >>> 3 2.5 5.0 >>> >>> 2.5 5.0 >>> input() input() 2 input() 2 input() input() 2 / 2 input() / 2 input() input() / 2 input()
  410. 410. Evaluated Input input 1 >>> input() >>> input() 1 >>> 2 1 + input() 3 1 + 2 >>> input() >>> input() 3 1 + 2 5.0 / 2 >>> input() 3 2.5 5.0 / 2 >>> input() >>> 2.5 input() 5.0 / 2 “aaa bbb” >>> input() read a string can be evaluated return an evaluated object
  411. 411. Evaluated Input input 1 + 2 >>> input() 3 >>> input() 1 >>> 2 1 + input() 5.0 / 3 1 + 2 2 >>> input() 2.5 >>> input() 3 1 + 2 5.0 / 2 >>> input() 3 “aaa 2 2.5 5.0 /bbb” >>> input() ‘aaa 2 >>> 2.5 input() 5.0 /bbb’ “aaa bbb” >>> input() read a string can be evaluated return an evaluated object
  412. 412. Evaluated Input input 1 + 2 >>> input() 3 >>> input() 1 >>> 2 1 + input() 5.0 / 3 1 + 2 2 >>> input() 2.5 >>> input() 3 1 + 2 5.0 / 2 >>> input() 3 “aaa 2 2.5 5.0 /bbb” >>> input() ‘aaa 2 >>> 2.5 input() 5.0 /bbb’ “aaa bbb” >>> input() read a string can be evaluated return an evaluated object
  413. 413. Evaluated Input input 3 1 + 2 >>> input() 3 >>> input() 1 5.0 / >>> 2 2 1 + input() 2.5 5.0 / 3 1 + 2 2 >>> input() 2.5 >>> input() 3 1 + 2 “aaa 2 5.0 /bbb” >>> input() 3 ‘aaa “aaa 2 2.5 bbb’ 5.0 /bbb” >>> input() ‘aaa 2 >>> 2.5 input() 5.0 /bbb’ [1, bbb” “aaa2, 3] >>> input() read a string can be evaluated return an evaluated object
  414. 414. Evaluated Input input 5.0 / 3 1 + 2 2 >>> input() 2.5 3 >>> input() 1 5.0 / >>> 2 2 1 + input() “aaa 2.5 5.0 / 2 3 1 + 2bbb” >>> input() ‘aaa 2.5 >>> input() 3 1 + 2bbb’ “aaa 2 5.0 /bbb” >>> input() 3 [1, ‘aaa “aaa bbb’ 2.5 2,23] 5.0 /bbb” >>> input() [1, ‘aaa >>> 2,23] 2.5 input() 5.0 /bbb’ [1, bbb” “aaa2, 3] >>> input() read a string can be evaluated return an evaluated object
  415. 415. Evaluated Input input 5.0 / 3 1 + 2 2 >>> input() 2.5 3 >>> input() 1 5.0 / >>> 2 2 1 + input() “aaa 2.5 5.0 / 2 3 1 + 2bbb” >>> input() ‘aaa 2.5 >>> input() 3 1 + 2bbb’ “aaa 2 5.0 /bbb” >>> input() 3 [1, ‘aaa “aaa bbb’ 2.5 2,23] 5.0 /bbb” >>> input() [1, ‘aaa >>> 2,23] 2.5 input() 5.0 /bbb’ [1, bbb” “aaa2, 3] >>> input() read a string can be evaluated return an evaluated object
  416. 416. Evaluated Input input 2.5 5.0 / 3 1 + 2 2 >>> input() 2.5 3 >>> input() 1 “aaa 5.0 / 2 >>> 2bbb” 1 + input() ‘aaa “aaa 2 2.5 5.0 /bbb’ 3 1 + 2bbb” >>> input() ‘aaa 2.5 >>> input() 3 1 + 2bbb’ [1, “aaa2,23] 5.0 /bbb” >>> input() 3 [1, ‘aaa “aaa bbb’ 2.5 2,23] 5.0 /bbb” >>> input() [1, ‘aaa >>> 2,23] 2.5 input() 5.0 /bbb’ 1 2 [1, bbb” “aaa2, 3] >>> input() read a string can be evaluated return an evaluated object
  417. 417. Evaluated Input input read a string can be evaluated return an evaluated object 2.5 5.0 / 3 1 + 2 2 >>> input() 2.5 3 >>> 1 2 input() Traceback “aaa 5.0 / 2 >>> 2bbb” (most recent call last): 1 + input() ‘aaa “aaa 2.5 5.0 /bbb’ 3 File2"<input>", line 1, in <module> 1 + 2bbb” >>> input() ‘aaa 2.5 >>> input() 3 File "<string>", line 1 1 + 2bbb’ [1, 1 “aaa2,23] 5.0 /bbb” >>> input() 3 [1, ‘aaa ^ “aaa bbb’ 2.5 2,23] 5.0 /bbb” >>> input() SyntaxError: [1, ‘aaa >>> 2,23] 2.5 input() unexpected EOF while parsing 5.0 /bbb’ 1 2 [1, bbb” “aaa2, 3] >>> input()
  418. 418. Raw Input read a string raw_input() return a string >>>
  419. 419. Raw Input read a string raw_input() return a string >>> raw_input()
  420. 420. Raw Input read a string raw_input() return a string >>> raw_input() 1
  421. 421. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>>
  422. 422. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>> raw_input()
  423. 423. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>> raw_input() 1 + 2
  424. 424. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>> raw_input() 1 + 2 ‘1 + 2’ >>>
  425. 425. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>> raw_input() 1 + 2 ‘1 + 2’ >>> raw_input()
  426. 426. Raw Input read a string raw_input() return a string >>> raw_input() 1 ‘1’ >>> raw_input() 1 + 2 ‘1 + 2’ >>> raw_input() 5.0 / 2
  427. 427. Raw Input read a string raw_input() return a string 1 >>> raw_input() ‘1’ 1 >>> ‘1’ raw_input() 1 + 2 >>> raw_input() ‘1 1 ++22’ >>> 2’ ‘1 +raw_input() 5.0 / 2 >>> raw_input() ‘5.0 5.0 //22’ >>>
  428. 428. Raw Input read a string raw_input() return a string ‘1’ 1 >>> raw_input() >>> ‘1’ raw_input() 1 1 + >>> 2 ‘1’ raw_input() ‘1 1 + 22’ >>>+raw_input() >>> ‘1 raw_input() 1 ++22’ 5.0 >>> /2’ ‘1 +raw_input() 2 ‘5.0 5.0 //22’ >>> raw_input() >>> ‘5.0raw_input() 5.0 //22’ >>> raw_input()
  429. 429. Raw Input read a string raw_input() return a string ‘1’ 1 >>> raw_input() >>> ‘1’ raw_input() 1 1 + >>> 2 ‘1’ raw_input() ‘1 1 + 22’ >>>+raw_input() >>> ‘1 raw_input() 1 ++22’ 5.0 >>> /2’ ‘1 +raw_input() 2 ‘5.0 5.0 //22’ >>> raw_input() >>> ‘5.0raw_input() 5.0 //22’ “aaa bbb” >>> raw_input()
  430. 430. Raw Input read a string raw_input() return a string ‘1’ 1 + 2 >>> raw_input() ‘1 >>> ‘1’ 2’ 1 +raw_input() 1 + >>> 2 ‘1’ raw_input() 5.0 ‘1 / 2 1 + 22’ >>>+raw_input() ‘5.0 >>> / ‘1 raw_input() 1 ++22’2’ 5.0 >>> /2’ ‘1 +raw_input() 2 “aaa ‘5.0 bbb” 5.0 //22’ >>> raw_input() ‘“aaa bbb”’ >>> ‘5.0raw_input() 5.0 //22’ “aaa bbb” >>> raw_input()
  431. 431. Raw Input read a string raw_input() return a string ‘1’ 1 + 2 >>> raw_input() ‘1 >>> ‘1’ 2’ 1 +raw_input() 1 + >>> 2 ‘1’ raw_input() 5.0 ‘1 / 2 1 + 22’ >>>+raw_input() ‘5.0 >>> / ‘1 raw_input() 1 ++22’2’ 5.0 >>> /2’ ‘1 +raw_input() 2 “aaa ‘5.0 bbb” 5.0 //22’ >>> raw_input() ‘“aaa bbb”’ >>> ‘5.0raw_input() 5.0 //22’ “aaa bbb” >>> raw_input()
  432. 432. Raw Input read a string raw_input() return a string ‘1 ‘1’ 1 + 22’ >>>+raw_input() ‘1 >>> ‘1’ 2’ 1 +raw_input() 5.0 1 + / >>> 2 2 ‘1’ raw_input() ‘5.0 5.0 ‘1 //2 1 + 22’2’ >>>+raw_input() ‘5.0 >>> / ‘1 raw_input() 1 ++22’2’ “aaa 2 5.0 bbb” >>> /2’ ‘1 +raw_input() ‘“aaa “aaa bbb”’ ‘5.0 bbb” 5.0 //22’ >>> raw_input() ‘“aaa bbb”’ >>> ‘5.0raw_input() 5.0 //22’ [1, bbb” “aaa2, 3] >>> raw_input()
  433. 433. Raw Input read a string raw_input() return a string 5.0 ‘1 ‘1’ / 2 1 + 22’ >>>+raw_input() ‘5.0 ‘1 >>> / ‘1’ 2’2’ 1 +raw_input() 5.0 1 + / >>> 2 2 ‘1’ raw_input() “aaa ‘5.0 5.0 bbb” ‘1 //2 1 + 22’2’ >>>+raw_input() ‘“aaa ‘5.0 >>> /bbb”’ ‘1 raw_input() 1 ++22’2’ “aaa 2 5.0 bbb” >>> /2’ ‘1 +raw_input() [1, ‘“aaa 3] “aaa bbb” ‘5.02,bbb”’ 5.0 //22’ >>> raw_input() ‘[1, ‘“aaa bbb”’ >>> 2, 3]’ ‘5.0raw_input() 5.0 //22’ [1, bbb” “aaa2, 3] >>> raw_input()
  434. 434. Raw Input read a string raw_input() return a string 5.0 ‘1 ‘1’ / 2 1 + 22’ >>>+raw_input() ‘5.0 ‘1 >>> / ‘1’ 2’2’ 1 +raw_input() 5.0 1 + / >>> 2 2 ‘1’ raw_input() “aaa ‘5.0 5.0 bbb” ‘1 //2 1 + 22’2’ >>>+raw_input() ‘“aaa ‘5.0 >>> /bbb”’ ‘1 raw_input() 1 ++22’2’ “aaa 2 5.0 bbb” >>> /2’ ‘1 +raw_input() [1, ‘“aaa 3] “aaa bbb” ‘5.02,bbb”’ 5.0 //22’ >>> raw_input() ‘[1, ‘“aaa bbb”’ >>> 2, 3]’ ‘5.0raw_input() 5.0 //22’ [1, bbb” “aaa2, 3] >>> raw_input()
  435. 435. Raw Input read a string raw_input() return a string ‘5.0 5.0 ‘1 ‘1’ //2 1 + 22’2’ >>>+raw_input() ‘5.0 ‘1 >>> / ‘1’ 2’2’ 1 +raw_input() “aaa 5.0 1 + / 2 >>> 2bbb” ‘1’ raw_input() ‘“aaa “aaa ‘5.0 bbb”’ 5.0 bbb” ‘1 //2 1 + 22’2’ >>>+raw_input() ‘“aaa ‘5.0 >>> /bbb”’ ‘1 raw_input() 1 ++22’2’ [1, “aaa bbb” 5.0 2,2 >>> /2’3] ‘1 +raw_input() ‘[1, [1, ‘“aaa2,3] “aaa bbb” ‘5.02,bbb”’ 5.0 //22’ >>> raw_input() 3]’ ‘[1, ‘“aaa bbb”’ >>> 2, 3]’ ‘5.0raw_input() 5.0 //22’ 1 2 [1, bbb” “aaa2, 3] >>> raw_input()
  436. 436. Raw Input read a string raw_input() return a string “aaa ‘5.0 5.0 bbb” ‘1 ‘1’ //2 1 + 22’2’ >>>+raw_input() ‘“aaa ‘5.0 ‘1 >>> /bbb”’ ‘1’ 2’2’ 1 +raw_input() “aaa 5.0 1 + / 2 >>> 2bbb” ‘1’ raw_input() [1, ‘“aaa “aaa ‘5.0 bbb” 5.0 2,bbb”’ ‘1 //23] 1 + 22’2’ >>>+raw_input() ‘[1, ‘“aaa ‘5.0 2, 3]’ >>> /bbb”’ ‘1 raw_input() 1 ++22’2’ [1, “aaa bbb” 5.0 2,2 >>> /2’3] ‘1 +raw_input() 1 2 ‘[1, [1, ‘“aaa2,3] “aaa bbb” ‘5.02,bbb”’ 5.0 //22’ >>> raw_input() 3]’ ‘1 ‘[1, ‘“aaa bbb”’ >>> raw_input() ‘5.0/2, 3]’ 5.02’/22’ 1 2 [1, bbb” “aaa2, 3] >>> raw_input()
  437. 437. Output print >>> print object to standard output
  438. 438. Output print print object to standard output >>> print “Hello World!”
  439. 439. Output print print object to standard output >>> print “Hello World!” Hello World! >>>
  440. 440. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!”
  441. 441. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!” Hello World! >>>
  442. 442. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!” Hello World! >>> print 1 + 2
  443. 443. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!” Hello World! >>> print 1 + 2 3 >>>
  444. 444. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!” Hello World! >>> print 1 + 2 3 >>> print [1, 2, 3]
  445. 445. Output print print object to standard output >>> print “Hello World!” Hello World! >>> print “Hello”, “World!” Hello World! >>> print 1 + 2 3 >>> print [1, 2, 3] [1, 2, 3] >>>
  446. 446. Custom Function
  447. 447. Define a Function >>>
  448. 448. Define a Function >>> def SQ(x):
  449. 449. Define a Function >>> def SQ(x): ...
  450. 450. Define a Function >>> def SQ(x): ... return x * x
  451. 451. Define a Function >>> def SQ(x): ... return x * x ...
  452. 452. Define a Function >>> def SQ(x): ... return x * x ... >>>
  453. 453. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10)
  454. 454. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10) 100 >>>
  455. 455. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10) 100 >>>
  456. 456. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10) 100 >>> function name
  457. 457. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10) 100 >>> function name parameter
  458. 458. Define a Function >>> def SQ(x): ... return x * x ... >>> SQ(10) 100 >>> function name parameter function content
  459. 459. Lambda Function >>>
  460. 460. Lambda Function >>> CUBE = lambda k: k * k * k
  461. 461. Lambda Function >>> CUBE = lambda k: k * k * k >>>
  462. 462. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10)
  463. 463. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>>
  464. 464. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>> (lambda x, y: x * y)(3, 4)
  465. 465. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>> (lambda x, y: x * y)(3, 4) 12 >>>
  466. 466. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>> (lambda x, y: x * y)(3, 4) 12 >>>
  467. 467. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>> (lambda x, y: x * y)(3, 4) 12 >>> parameter
  468. 468. Lambda Function >>> CUBE = lambda k: k * k * k >>> CUBE(10) 1000 >>> (lambda x, y: x * y)(3, 4) 12 >>> return value parameter
  469. 469. Built-in Function
  470. 470. range >>>
  471. 471. range >>> range(10)
  472. 472. range >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>>
  473. 473. range >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(3, 10)
  474. 474. range >>> [0, >>> [3, >>> range(10) 1, 2, 3, 4, 5, 6, 7, 8, 9] range(3, 10) 4, 5, 6, 7, 8, 9]
  475. 475. range >>> [0, >>> [3, >>> range(10) 1, 2, 3, 4, 5, 6, 7, 8, 9] range(3, 10) 4, 5, 6, 7, 8, 9] range(1, 10, 2)
  476. 476. range >>> [0, >>> [3, >>> [1, >>> range(10) 1, 2, 3, 4, 5, 6, 7, 8, 9] range(3, 10) 4, 5, 6, 7, 8, 9] range(1, 10, 2) 3, 5, 7, 9]

×