파이썬 기초
TRANSCRIPT
PowerPoint
Python Moon Yong Joon1
2
zen of python3
zen of python
4
platform5
platform module platform
6
7
8
Python 2to3 http://www.diveintopython3.net/porting-code-to-python-3-with-2to3.html
9
__future__10
3.X Python 2to3
print 11
/
12
literal expression13
literal expression literal expression ,
14
15
16
OperatorDescription**Exponentiation (raise to the power)~ + -Ccomplement, unary plus and minus (method names for the last two are +@ and -@)* / % //Multiply, divide, modulo and floor division+ -Addition and subtraction>> =Comparison operators == !=Equality operators= %= /= //= -= += *= **=Assignment operatorsis is notIdentity operatorsin not inMembership operatorsnot or andLogical operators
17
Division : 18
, operator
2. int 3. __future__ division import 3. 19
special method / __truediv__ // __floordiv__
20
21
Expression
22
Expression generator
Generator expression 23
24
25
var, obj var obj class var, obj
26
( Reference Variable) , Variable ,
Variable = ()
( )27
28
29
None Variable ,
Variable = ()
30
i
31
(value & Type)
32
33
instance object class object Class objectInstanceobject
Type Value new
Value/Type34
35
(Variable) (object) ,
Variable ,
Variable = ()36
Type 37
Type inference l . .
.
38
39
new
40
Int Float int isdigit() True
41
float int float
42
43
44
//
45
46
: , ,,,
47
( ) Private (property, ) Private( ) , (special method) 48
49
namespace
namespaceoperator
operator 50
Special 51
Special __special__
52
Keywords
53
Keyword54
Keyword keyword keyword import (2.7)
55
Keyword : 2.x 2.7 Keywordandelififprintaselseimportraiseassertexceptinreturnbreakexecistryclassfinallylambdawhilecontinuefornotwithdeffromoryielddelglobalpass
56
Keyword : print(2.x) 2.x 3. __future__ import print
57
Keyword : 3.x 3.x Keywordandelifimportraiseaselseinreturnassertexceptistrybreakfinallylambdawhileclassfor nonlocalwithcontinuefromnotyielddefglobalordelifpass
58
print59
Print : 2.7 print
60
61
62
=
iii + 1 Unbinding (NameError: name 'iii' is not defined)63
binding() Scope I + 1 I I NameError: name 'i' is not defined ( ) .
64
65
namespace , class, instance global globals() locals()class __dict__instance __dict__66
class method : class class namespace class. GlobalCount = 100Class AA.Count = 1
67
68
Reference Variable () reference binding
dir() context 69
namespace: dict type global . Globals context
70
namespace: globals [], = global
71
binding 72
Variable
73
74
75
Variable Context .del , del()
76
77
Chained Assignments78
.
79
Augmented Assignments80
.
81
operator
82
Operator 83
84
85
OperatorDescriptionExample+AdditionAdds values on either side of the operator.a + b = 30- SubtractionSubtracts right hand operand from left hand operand.a b = -10* MultiplicationMultiplies values on either side of the operatora * b = 200/ DivisionDivides left hand operand by right hand operandb / a = 2% ModulusDivides left hand operand by right hand operand and returns remainderb % a = 0** ExponentPerforms exponential (power) calculation on operatorsa**b =10 to the power 20//Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed.9//2 = 4 and 9.0//2.0 = 4.0
86
OperatorDescriptionExample=Assigns values from right side operands to left side operandc = a + b assigns value of a + b into c+= Add ANDIt adds right operand to the left operand and assign the result to left operandc += a is equivalent to c = c + a-= Subtract ANDIt subtracts right operand from the left operand and assign the result to left operandc -= a is equivalent to c = c - a*= Multiply ANDIt multiplies right operand with the left operand and assign the result to left operandc *= a is equivalent to c = c * a/= Divide ANDIt divides left operand with the right operand and assign the result to left operandc /= a is equivalent to c = c / ac /= a is equivalent to c = c / a%= Modulus ANDIt takes modulus using two operands and assign the result to left operandc %= a is equivalent to c = c % a**= Exponent ANDPerforms exponential (power) calculation on operators and assign value to the left operandc **= a is equivalent to c = c ** a//= Floor DivisionIt performs floor division on operators and assign value to the left operandc //= a is equivalent to c = c // a
87
: and, or, xorOperatorDescription& Binary AND | Binary OR ^ Binary XOR
88
: ~, OperatorDescription~ Binary Ones Complement1 > Binary Right Shift .
89
90
OperatorDescriptionExampleand Logical ANDIf both the operands are true then condition becomes true.(a and b) is true.or Logical ORIf any of the two operands are non-zero then condition becomes true.(a or b) is true.not Logical NOTUsed to reverse the logical state of its operand.Not(a and b) is false.
91
92
: and/or
and : true and : false
or : true or : false 93
94
OperatorDescriptionExample==If the values of two operands are equal, then the condition becomes true.(a == b) is not true.!=If values of two operands are not equal, then condition becomes true.If values of two operands are not equal, then condition becomes true.(a b) is true. This is similar to != operator.>If the value of left operand is greater than the value of right operand, then condition becomes true.(a > b) is not true.=If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.(a >= b) is not true.