SlideShare a Scribd company logo
1 of 44
Download to read offline
What is Python?
http://www.python.org
Platform Independent
Interpreter
Object-oriented
Dynamically typed
Interactive
Script Mode
Interactive Mode
>>> import antigravity
Why Python?
Easy
Powerful
Extensible and Flexible
Interpreted
Object-oriented
Dynamic
Orthogonally structured
Embeddable
And Free
The Zen of Python, by Tim Peters
!
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>> import this
파이썬의 선(禪) 팀 피터슨
!
아름다움이 추함보다 좋다.
명시가 암시보다 좋다.
단순함이 복잡함보다 좋다.
복잡함이 꼬인 것보다 좋다.
수평이 계층보다 좋다.
여유로운 것이 밀집한 것보다 좋다.
가독성은 중요하다.
특별한 경우라는 것은 규칙을 어겨야 할 정도로 특별한 것이 아니다.
허나 실용성은 순수성에 우선한다.
오류 앞에서 절대 침묵하지 말지어다.
명시적으로 오류를 감추려는 의도가 아니라면.
모호함을 앞에 두고, 이를 유추하겠다는 유혹을 버려라.
어떤 일에든 명확하고 바람직하며 유일한 방법이 존재한다.
비록 그대가 우둔하여 그 방법이 처음에는 명확해 보이지 않을지라도.
지금 하는게 아예 안하는 것보다 낫다.
아예 안하는 것이 지금 *당장*보다 나을 때도 있지만.
구현 결과를 설명하기 어렵다면, 그 아이디어는 나쁘다.
구현 결과를 설명하기 쉽다면, 그 아이디어는 좋은 아이디어일 수 있다.
네임스페이스는 대박이다 -- 마구 남용해라!
>>>
C vs Java vs Python
C, Hello World
#include <stdio.h>	
int main(int argc, char *argv[]) 	
{	
	 printf("Hello World n");	
	 return 0;	
}
JAVA, Hello World
class HelloWorld {	
	 public static void main(String[] args) {	
	 	 System.out.println("Hello World");	
	 }	
}
Python, Hello World
print "Hello World"
Find Array Value, C
#include <stdio.h>	
!
#define ARR_LEN 5	
!
int main(int argc, char *argv[]) 	
{	
	 int nArr[ARR_LEN] = {10, 20, 30, 40, 50};	
	 int nVal=20;	
	 int i, nCnt=0;	
	 	
	 for(i=0; i<ARR_LEN; i++)	
	 {	
	 	 if(nArr[i] == nVal)	
	 	 {	
	 	 	 printf("True %d n", nVal);	
	 	 	 break;	
	 	 }	
	 	 else nCnt++;	
	 }	
	 if(nCnt == ARR_LEN) printf("False %d n", nVal);	
	 	
	 return 0;	
}
Find Array Value, JAVA
class TestClass {	
	 public static void main(String[] args) {	
	 	 Integer nArr[] = {10, 20, 30, 40, 50};	
	 	 int nVal = 60;	
	 	 int nCnt=0;	 	
	 	 	 	
	 	 for(int i=0; i<nArr.length; i++){	
	 	 	 if(nVal == nArr[i]){	
	 	 	 	 System.out.println("True : "+nVal);	
	 	 	 	 break;	
	 	 	 }	
	 	 	 else nCnt++;	
	 	 }	
	 	 if(nCnt==nArr.length)	
	 	 	 System.out.println("False : "+nVal);	
	 }	
}
Find Array Value, Python
nArr = [10, 20, 30, 40, 50]	
nVal = 20	
if nVal in nArr:	
	 print"True %d" % (nVal)	
else:	
	 print "False %d " % (nVal)
Indent
Indent of C
int main(int argc, char *argv[]) 	
{	
	 printf("Hello World n");	
	 return 0;	
}	
!
int main(int argc, char *argv[]) 	
{	printf("Hello World n");	return 0;}	
!
int main(int argc, char *argv[]){	
printf("Hello World n");	
return 0;}
Indent of Python
if a == 10:	
	 print "a : 10"	
else:	
	 print "a : %d" % (a)
if a == 10: print "a : 10"	
else: print "a : %d" % (a)
if a == 10: 	
	 print "a : 10"	
else:	
	 print "a : %d" % (a)	
	 	 print ("Done") # Error !!
def func(nNum):	
	 nNum+=1	
	 return nNum	
def func(nNum):	
	 nNum+=1	
	 	 print "Error" # Error	
	 return nNum
class Bird(object):	
	 head = 1	
	 body = 1	
	 wing = 2	
	 leg = 2	
	 	
	 def fly(self):	
	 	 print "Fly"
Data Type
Everything is object
a = 10	
b = 20	
c = 10	
!
print "1) a ID : %d " % (id(a))	
print "2) 10 ID : %d " % (id(10))	
print "3) b ID : %d " % (id(b))	
print "4) 20 ID : %d " % (id(20))	
print "5) c ID : %d " % (id(c))
1) a ID : 140286848207040
2) 10 ID : 140286848207040
3) b ID : 140286848206800
4) 20 ID : 140286848206800
5) c ID : 140286848207040
Number
String
List
Tuple
Dictionary
Number
• Integer
nANum = 10	
nBNum = -10	
nCNum = 0
• Floating-point number
nfANum = 1.2	
nfBNum = -3.45	
nfCNum = 4.24E10	
nfDNum = 4.24e-10
Number
• Octal
• Hexadecimal
• Complex number
noANum = 0o177
nhANum = 0xFFF1
nCNum = 10+2j	
print nCNum	
print nCNum.real	
print nCNum.imag
Number operations
nA = 10	
nB = 20 	
!
print nA+nB	
print nA-nB	
print nB/nA	
print 30%11	
print 2**10
String
str1 = "Hello World" 	
print str1	
!
str2 = 'Python is fun' 	
print str2	
!
str3 = """Life is too short, You need python""" 	
print str3	
!
str4 = '''Life is too shor, You need python'''	
print str4	
!
str5 = "Python's favorite food is perl"	
print str5	
!
str6 = '"Python is very easy." he says.' 	
print str6	
!
str7= "Life is too shortnYou need python"	
print str7
Hello World
Python is fun
Life is too short, You need python
Life is too short, You need python
Python's favorite food is perl
"Python is very easy." he says.
Life is too short
You need python
String operation
head = "Python"	
tail = " is fun!"	
print(head + tail)	
!
!
a = "python"	
print(a * 2)	
!
!
print("=" * 11)	
print("My Program")	
print("=" * 11)
Python is fun!
pythonpython
===========
My Program
===========
str1 = "Life is too short, You need Python"	
print str1[0]	
!
!
print str1[-1]	
!
!
str2 = str1[0] + str1[1] + str1[2] + str1[3]	
print str2	
!
!
str3 = str1[0:4]	
print str2	
!
!
str4 = str1[19:]	
print str4	
!
!
str5 = str1[:17]	
print str5
L
n
Life
Life
You need Python
Life is too short
List
Array
List
!
emptyList = []	
nList = [10, 20, 30, 40, 50]	
szList = ["Kim", "Dae", "Gap"]	
stList = ["Kim", "Dae", "Gap", 10, 20]	
!
print emptyList	
print nList	
print szList	
print stList
->Result
[]
[10, 20, 30, 40, 50]
['Kim', 'Dae', 'Gap']
['Kim', 'Dae', 'Gap', 10, 20]
List
nList.append(60)	
print nList	
!
szList.insert(1, '-')	
print szList	
!
del stList[3]	
print stList
-> Result
[10, 20, 30, 40, 50, 60]
['Kim', '-', 'Dae', ‘Gap']
['Kim', 'Dae', 'Gap', 20]
Tuple
Constancy
Tuple
tTu1 = ()	
tTu2 = (10,)	
tTu3 = (10, 20, 30)	
tTu4 = 10, 20, 30	
tTu5 = ('Kim', 10, 'Dae', 20, 'Gap')	
!
print tTu1	
print tTu2	
print tTu3	
print tTu4	
print tTu5	
—> Result
()
(10,)
(10, 20, 30)
(10, 20, 30)
('Kim', 10, 'Dae', 20, 'Gap')
Tuple
lName = ["Kim Dae-Gap", "Sistar", "Girlsday", "Psy"]	
lAge = [29, 22, 20, 38]	
lAddr = ["Suwon", "Seoul", "Pusan", "Gang-Nam"]	
tProfile = (lName, lAge, lAddr)	
print tProfile	
!
tProfile[0].append("JYP")	
tProfile[1].append(40)	
tProfile[2].append("NY")	
print tProfile
—> Result
(['Kim Dae-Gap', 'Sistar', 'Girlsday', 'Psy'], [29, 22, 20, 38], ['Suwon', 'Seoul', 'Pusan', 'Gang-Nam'])
(['Kim Dae-Gap', 'Sistar', 'Girlsday', 'Psy', 'JYP'], [29, 22, 20, 38, 40], ['Suwon', 'Seoul', 'Pusan', 'Gang-Nam', 'NY'])
Dictionary
Key = Value
Dictionary
dProfile = {'name':'dgkim', 'phone':'01040575212', 'birthyday': '0127'}	
print dProfile	
!
!
print dProfile['name']	
!
!
dProfile['addr'] = 'suwon'	
print dProfile[‘addr']	
!
!
print dProfile.keys()	
!
!
print dProfile.values()
if 'name' in dProfile:	
	 print dProfile.get('name')	
else:	
	 print "no name”	
!
!
!
dProfile.clear()	
print dProfile
{'phone': '01040575212', 'name': 'dgkim', 'birthyday': '0127'}
dgkim
suwon
['addr', 'phone', 'name', 'birthyday']
['suwon', '01040575212', 'dgkim', '0127']
Function and Class
Function
def funcSum(a, b):	
	 rst = a+b	
	 return rst	
def manyArg(type, *args): 	
	 sum = 0 	
	 print type	
	 for i in args: 	
	 	 sum = sum + i 	
	 return sum
print funcSum(10, 10) print manyArg('type', 10, 20, 30, 40)
20 type
100
Classclass profile:	
	 def __init__(self):	
	 	 self.name = ''	
	 	 self.age = 0	
	 	 self.addr = ''	
	 	
	 def setName(self, name):	
	 	 self.name = name	
	 	
	 def setAge(self, age):	
	 	 self.age = age	
	 	
	 def setAddr(self, addr):	
	 	 self.addr = addr	
	 	 	
	 def __str__(self):	
	 	 str = ''	
	 	 str += ('='*20)+'n'	
	 	 str += "Name : %s n" % (self.name)	
	 	 str += "Age : %d n" % (self.age)	
	 	 str += "Addr : %s n" % (self.addr)	
	 	 str += ('='*20)+'n'	
	 	 return str	
	 	
pro = profile()	
pro.setName('dgkim')	
pro.setAge(29)	
pro.setAddr('suwon')	
!
print pro
====================
Name : dgkim
Age : 29
Addr : suwon
====================
Class
class member(profile):	
	 	
	 def __init__(self):	
	 	 profile.__init__(self)	
	 	 self.desc =''	
	 	
	 def setDesc(self, desc):	
	 	 self.desc = desc	
	 	 	
	 def __str__(self):	
	 	 str = ''	
	 	 str += ('='*20)+'n'	
	 	 str += "Name : %s n" % (self.name)	
	 	 str += "Age : %d n" % (self.age)	
	 	 str += "Addr : %s n" % (self.addr)	
	 	 str += "desc : %s n" % (self.desc)	
	 	 str += ('='*20)+'n'	
	 	 return str
!
mem = member()	
mem.setName('KKK')	
mem.setAge(22)	
mem.setAddr('seoul')	
mem.setDesc('Solo')	
print mem
====================
Name : KKK
Age : 22
Addr : seoul
desc : Solo
====================
Reference
• Official site http://python.org/
• Study site http://www.codecademy.com/tracks/python
• WiKi docs https://wikidocs.net/book/1
How can use the Python for IPRON ?

More Related Content

What's hot

What's hot (20)

Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Python programming
Python  programmingPython  programming
Python programming
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Python
PythonPython
Python
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Python
PythonPython
Python
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
 
Python
PythonPython
Python
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Python ppt
Python pptPython ppt
Python ppt
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-Programmers
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python Session - 3
Python Session - 3Python Session - 3
Python Session - 3
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 

Viewers also liked (11)

Taller arancelario notass
Taller arancelario notassTaller arancelario notass
Taller arancelario notass
 
Saude brasileiros revista lancet
Saude brasileiros revista lancetSaude brasileiros revista lancet
Saude brasileiros revista lancet
 
Scannning and indexing_operations
Scannning and indexing_operationsScannning and indexing_operations
Scannning and indexing_operations
 
Device interface (090721)
Device interface (090721)Device interface (090721)
Device interface (090721)
 
Bases de datos
Bases de datosBases de datos
Bases de datos
 
Guia de laboratorio nº 2
Guia de laboratorio nº 2Guia de laboratorio nº 2
Guia de laboratorio nº 2
 
D&G presentación oficial
D&G presentación oficialD&G presentación oficial
D&G presentación oficial
 
Saude brasileiros revista lancet
Saude brasileiros revista lancetSaude brasileiros revista lancet
Saude brasileiros revista lancet
 
Radiação gama
Radiação gamaRadiação gama
Radiação gama
 
02 pauta y_tabla_de_notacion_interna0
02 pauta y_tabla_de_notacion_interna002 pauta y_tabla_de_notacion_interna0
02 pauta y_tabla_de_notacion_interna0
 
Guia de laboratorio nº 2
Guia de laboratorio nº 2Guia de laboratorio nº 2
Guia de laboratorio nº 2
 

Similar to Python

Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
aztack
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
bleis tift
 

Similar to Python (20)

Ruby Language - A quick tour
Ruby Language - A quick tourRuby Language - A quick tour
Ruby Language - A quick tour
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Class 2: Welcome part 2
Class 2: Welcome part 2Class 2: Welcome part 2
Class 2: Welcome part 2
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Python basic
Python basic Python basic
Python basic
 
Python slide
Python slidePython slide
Python slide
 
Idioms in swift 2016 05c
Idioms in swift 2016 05cIdioms in swift 2016 05c
Idioms in swift 2016 05c
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Python crush course
Python crush coursePython crush course
Python crush course
 
仕事で使うF#
仕事で使うF#仕事で使うF#
仕事で使うF#
 
C tutorial
C tutorialC tutorial
C tutorial
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
python codes
python codespython codes
python codes
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Music as data
Music as dataMusic as data
Music as data
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Vcs16
Vcs16Vcs16
Vcs16
 

Recently uploaded

Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
Jaipur ❤CALL GIRL 0000000000❤CALL GIRLS IN Jaipur ESCORT SERVICE❤CALL GIRL IN...
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Signal Processing and Linear System Analysis
Signal Processing and Linear System AnalysisSignal Processing and Linear System Analysis
Signal Processing and Linear System Analysis
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 

Python

  • 1.
  • 5.
  • 9. The Zen of Python, by Tim Peters ! Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those! >>> import this
  • 10. 파이썬의 선(禪) 팀 피터슨 ! 아름다움이 추함보다 좋다. 명시가 암시보다 좋다. 단순함이 복잡함보다 좋다. 복잡함이 꼬인 것보다 좋다. 수평이 계층보다 좋다. 여유로운 것이 밀집한 것보다 좋다. 가독성은 중요하다. 특별한 경우라는 것은 규칙을 어겨야 할 정도로 특별한 것이 아니다. 허나 실용성은 순수성에 우선한다. 오류 앞에서 절대 침묵하지 말지어다. 명시적으로 오류를 감추려는 의도가 아니라면. 모호함을 앞에 두고, 이를 유추하겠다는 유혹을 버려라. 어떤 일에든 명확하고 바람직하며 유일한 방법이 존재한다. 비록 그대가 우둔하여 그 방법이 처음에는 명확해 보이지 않을지라도. 지금 하는게 아예 안하는 것보다 낫다. 아예 안하는 것이 지금 *당장*보다 나을 때도 있지만. 구현 결과를 설명하기 어렵다면, 그 아이디어는 나쁘다. 구현 결과를 설명하기 쉽다면, 그 아이디어는 좋은 아이디어일 수 있다. 네임스페이스는 대박이다 -- 마구 남용해라! >>>
  • 11. C vs Java vs Python
  • 12. C, Hello World #include <stdio.h> int main(int argc, char *argv[]) { printf("Hello World n"); return 0; }
  • 13. JAVA, Hello World class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } }
  • 14. Python, Hello World print "Hello World"
  • 15. Find Array Value, C #include <stdio.h> ! #define ARR_LEN 5 ! int main(int argc, char *argv[]) { int nArr[ARR_LEN] = {10, 20, 30, 40, 50}; int nVal=20; int i, nCnt=0; for(i=0; i<ARR_LEN; i++) { if(nArr[i] == nVal) { printf("True %d n", nVal); break; } else nCnt++; } if(nCnt == ARR_LEN) printf("False %d n", nVal); return 0; }
  • 16. Find Array Value, JAVA class TestClass { public static void main(String[] args) { Integer nArr[] = {10, 20, 30, 40, 50}; int nVal = 60; int nCnt=0; for(int i=0; i<nArr.length; i++){ if(nVal == nArr[i]){ System.out.println("True : "+nVal); break; } else nCnt++; } if(nCnt==nArr.length) System.out.println("False : "+nVal); } }
  • 17. Find Array Value, Python nArr = [10, 20, 30, 40, 50] nVal = 20 if nVal in nArr: print"True %d" % (nVal) else: print "False %d " % (nVal)
  • 19. Indent of C int main(int argc, char *argv[]) { printf("Hello World n"); return 0; } ! int main(int argc, char *argv[]) { printf("Hello World n"); return 0;} ! int main(int argc, char *argv[]){ printf("Hello World n"); return 0;}
  • 20. Indent of Python if a == 10: print "a : 10" else: print "a : %d" % (a) if a == 10: print "a : 10" else: print "a : %d" % (a) if a == 10: print "a : 10" else: print "a : %d" % (a) print ("Done") # Error !! def func(nNum): nNum+=1 return nNum def func(nNum): nNum+=1 print "Error" # Error return nNum class Bird(object): head = 1 body = 1 wing = 2 leg = 2 def fly(self): print "Fly"
  • 23.
  • 24. a = 10 b = 20 c = 10 ! print "1) a ID : %d " % (id(a)) print "2) 10 ID : %d " % (id(10)) print "3) b ID : %d " % (id(b)) print "4) 20 ID : %d " % (id(20)) print "5) c ID : %d " % (id(c)) 1) a ID : 140286848207040 2) 10 ID : 140286848207040 3) b ID : 140286848206800 4) 20 ID : 140286848206800 5) c ID : 140286848207040
  • 26. Number • Integer nANum = 10 nBNum = -10 nCNum = 0 • Floating-point number nfANum = 1.2 nfBNum = -3.45 nfCNum = 4.24E10 nfDNum = 4.24e-10
  • 27. Number • Octal • Hexadecimal • Complex number noANum = 0o177 nhANum = 0xFFF1 nCNum = 10+2j print nCNum print nCNum.real print nCNum.imag
  • 28. Number operations nA = 10 nB = 20 ! print nA+nB print nA-nB print nB/nA print 30%11 print 2**10
  • 29. String str1 = "Hello World" print str1 ! str2 = 'Python is fun' print str2 ! str3 = """Life is too short, You need python""" print str3 ! str4 = '''Life is too shor, You need python''' print str4 ! str5 = "Python's favorite food is perl" print str5 ! str6 = '"Python is very easy." he says.' print str6 ! str7= "Life is too shortnYou need python" print str7 Hello World Python is fun Life is too short, You need python Life is too short, You need python Python's favorite food is perl "Python is very easy." he says. Life is too short You need python
  • 30. String operation head = "Python" tail = " is fun!" print(head + tail) ! ! a = "python" print(a * 2) ! ! print("=" * 11) print("My Program") print("=" * 11) Python is fun! pythonpython =========== My Program =========== str1 = "Life is too short, You need Python" print str1[0] ! ! print str1[-1] ! ! str2 = str1[0] + str1[1] + str1[2] + str1[3] print str2 ! ! str3 = str1[0:4] print str2 ! ! str4 = str1[19:] print str4 ! ! str5 = str1[:17] print str5 L n Life Life You need Python Life is too short
  • 32. List ! emptyList = [] nList = [10, 20, 30, 40, 50] szList = ["Kim", "Dae", "Gap"] stList = ["Kim", "Dae", "Gap", 10, 20] ! print emptyList print nList print szList print stList ->Result [] [10, 20, 30, 40, 50] ['Kim', 'Dae', 'Gap'] ['Kim', 'Dae', 'Gap', 10, 20]
  • 33. List nList.append(60) print nList ! szList.insert(1, '-') print szList ! del stList[3] print stList -> Result [10, 20, 30, 40, 50, 60] ['Kim', '-', 'Dae', ‘Gap'] ['Kim', 'Dae', 'Gap', 20]
  • 35. Tuple tTu1 = () tTu2 = (10,) tTu3 = (10, 20, 30) tTu4 = 10, 20, 30 tTu5 = ('Kim', 10, 'Dae', 20, 'Gap') ! print tTu1 print tTu2 print tTu3 print tTu4 print tTu5 —> Result () (10,) (10, 20, 30) (10, 20, 30) ('Kim', 10, 'Dae', 20, 'Gap')
  • 36. Tuple lName = ["Kim Dae-Gap", "Sistar", "Girlsday", "Psy"] lAge = [29, 22, 20, 38] lAddr = ["Suwon", "Seoul", "Pusan", "Gang-Nam"] tProfile = (lName, lAge, lAddr) print tProfile ! tProfile[0].append("JYP") tProfile[1].append(40) tProfile[2].append("NY") print tProfile —> Result (['Kim Dae-Gap', 'Sistar', 'Girlsday', 'Psy'], [29, 22, 20, 38], ['Suwon', 'Seoul', 'Pusan', 'Gang-Nam']) (['Kim Dae-Gap', 'Sistar', 'Girlsday', 'Psy', 'JYP'], [29, 22, 20, 38, 40], ['Suwon', 'Seoul', 'Pusan', 'Gang-Nam', 'NY'])
  • 38. Dictionary dProfile = {'name':'dgkim', 'phone':'01040575212', 'birthyday': '0127'} print dProfile ! ! print dProfile['name'] ! ! dProfile['addr'] = 'suwon' print dProfile[‘addr'] ! ! print dProfile.keys() ! ! print dProfile.values() if 'name' in dProfile: print dProfile.get('name') else: print "no name” ! ! ! dProfile.clear() print dProfile {'phone': '01040575212', 'name': 'dgkim', 'birthyday': '0127'} dgkim suwon ['addr', 'phone', 'name', 'birthyday'] ['suwon', '01040575212', 'dgkim', '0127']
  • 40. Function def funcSum(a, b): rst = a+b return rst def manyArg(type, *args): sum = 0 print type for i in args: sum = sum + i return sum print funcSum(10, 10) print manyArg('type', 10, 20, 30, 40) 20 type 100
  • 41. Classclass profile: def __init__(self): self.name = '' self.age = 0 self.addr = '' def setName(self, name): self.name = name def setAge(self, age): self.age = age def setAddr(self, addr): self.addr = addr def __str__(self): str = '' str += ('='*20)+'n' str += "Name : %s n" % (self.name) str += "Age : %d n" % (self.age) str += "Addr : %s n" % (self.addr) str += ('='*20)+'n' return str pro = profile() pro.setName('dgkim') pro.setAge(29) pro.setAddr('suwon') ! print pro ==================== Name : dgkim Age : 29 Addr : suwon ====================
  • 42. Class class member(profile): def __init__(self): profile.__init__(self) self.desc ='' def setDesc(self, desc): self.desc = desc def __str__(self): str = '' str += ('='*20)+'n' str += "Name : %s n" % (self.name) str += "Age : %d n" % (self.age) str += "Addr : %s n" % (self.addr) str += "desc : %s n" % (self.desc) str += ('='*20)+'n' return str ! mem = member() mem.setName('KKK') mem.setAge(22) mem.setAddr('seoul') mem.setDesc('Solo') print mem ==================== Name : KKK Age : 22 Addr : seoul desc : Solo ====================
  • 43. Reference • Official site http://python.org/ • Study site http://www.codecademy.com/tracks/python • WiKi docs https://wikidocs.net/book/1
  • 44. How can use the Python for IPRON ?