SlideShare ist ein Scribd-Unternehmen logo
1 von 77
Downloaden Sie, um offline zu lesen
Python Tutorial
For Beginners
对
2015-11-20
http://pqx.ee/
Intro
时
Python
/ˈpaɪθɑːn/ in us
or
/ˈpaɪθən/ in uk
Created By
Guido van Rossum
in 1989
- 1989 快以可
⽣生起 快 “ ”
- ABC 快 ⼤大
perl lisp
-
Monty Python's Flying Circus
BBC 来
Features and philosophy
• 了 了
• 了 中⼀一 了
• ( )
• 著
• ( & )
Language Features
• Beautiful is better than ugly
• Explicit is better than implicit
• Simple is better than complex
• Complex is better than complicated
• Readability counts
The Zen of Python
there should be one
and preferably only one
obvious way to do it
快
• 和
• 发好
batteries included
快
• GUI
•
•
为过成
“ ⾃自” “ 上” “ ”
Use
• Web Web
• Scipy Numpy
• 有 (google TensorFlow)
• GUI PyQT wxWorks
• ( perl bash)
•
Python 也
Python
Raspberry Pi python GPIO
Pi python
quick start
Installation /
• brew install python
• apt-get install python
• yum install python
• … also, binary Installer for Windows
Hello World
print “hello world”
• Just as simple as
Interrupter / 能
能 evaluate
能
有
有
能
* python
能
能
run python code /
$ python helloWorld.py
• python 有
• CPython • IPython
• PyPy
• IronPyton
• Jython
run python code /
• REPL 也
$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on
darwin
Type "help", "copyright", "credits" or "license" for more
information.
>>> print "hello world"
hello world
(Read-Eval-Print Loop)
Mathematics /
+, -, *, /, //, %, **
出 (3.5 ) @
==, >, <, >=, <=, !=
and, or, not
=, +=, -=, *=, /=, %=
variables /
x = 1
x = ‘hello world!’
• 了 快
•
• 好
Mathematics /
• (++) 不(--)
x = 3
x += 1
x -= 2
indentation /
if x >= 60:
print ‘passed!’
else:
print ‘failed!’
• { }
python
• 快
•
• 没
多
• ...
comments /
# comments in single line
•
•
'''comments in multi line
line 2
line 3
'''
conditions /
if x >= 90:
print ‘A’
elif x >= 75:
print ‘B’
elif x >= 60:
print ‘C’
else:
print ‘D’
• if else elif
conditions /
switch !!!
成if... elif... elif... else
loops /
x = 0
while(x<100):
x = 1
print x
• while
loops /
for i in range(100):
print i
• for..in..
loops /
• continue break
(c java )
x = 0
while True:
x = x + 1
if x > 100:
break
loops /
• while for..in..
• do..while
• until
• goto
data structures
numbers /
• int
• float
• complex
str /
• 好
• % format
•
list /
•
• 的
• (List comprehensions)
dict / 都( )
•
• 的
tuple / 个
• 快 都 key
• list ,
• 新
set / 是
• 新 list
>>> set([1, 2, 3, 4, 1, 2])
set([1, 2, 3, 4])
bool /
• True / False
• python :
None
• False
•
• int
• float
• complex
Mutable Immutable
• str
• list
• set
• dict
• tuple
•
functions
function /
• 快 None
def square(x):
return x*x
• 要
快 快
def pow(x, y=2):
return x**y
好 在
• 好 在
pow(y=3, x=2)
• *
def square_sum(*values):
s = 0
for i in values:
s += i*i
return s
( )
• * *
def print_values(**values):
for k in values:
print ‘%s => %s’ % (k, values[k])
class and objects
了
class / 了 好
class Animal():
def __init__(self, name):
self.name = name
def sayHi(self):
print self.name, 'says Hi!'
builtin method / 要
• __init__
• __del__
• __repr__
• __str__
• __unicode__
• 会
•
__x _classname__x
class Cat(Animal):
def __init__(self, name='kitty'):
self.name = name
def sayHi(self):
print ‘hello %s mio!’ % self.name
了
• 了
•
• 1+2 (1).__add__(2)
•
module and import
module /
• 最
• sys.modules
开
开 PYTHONPATH
开 要
import /
• 快
• (__import__)
• execfile
input and output
下 下
IO
• raw_input (python3 input)
• sys.stdin sys.stdout
• print
• open
• read
• write
json
• dumps
• loads
advanced features
• lambda ( )
•
• map reduce filter
•
—
• dir hasattr getattr setattr
• eval exec
• locals globals
要
• 成 __doc__ __name__ __file__
• : __dict__ __class__
• 了: __doc__ __module__ __dict__
__bases__
• yield 有
• 有
• 了
• C/C++ 分 python
summary
• 了 了
• 了 中⼀一 了
• ( )
• 著
• ( & )
Features /
https://github.com/vinta/awesome-python
去 C
JAVA C#
Python !!!

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Python ppt
Python pptPython ppt
Python ppt
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python basics
Python basicsPython basics
Python basics
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
 
The Benefits of Type Hints
The Benefits of Type HintsThe Benefits of Type Hints
The Benefits of Type Hints
 
Python Presentation
Python PresentationPython Presentation
Python Presentation
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
PYTHON NOTES
PYTHON NOTESPYTHON NOTES
PYTHON NOTES
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
Learn python – for beginners
Learn python – for beginnersLearn python – for beginners
Learn python – for beginners
 

Andere mochten auch

Python简明教程
Python简明教程Python简明教程
Python简明教程
ingong
 
BIOS and Secure Boot Attacks Uncovered
BIOS and Secure Boot Attacks UncoveredBIOS and Secure Boot Attacks Uncovered
BIOS and Secure Boot Attacks Uncovered
Alex Matrosov
 
Intel ssd dc data center family for PCIe
Intel ssd dc data center family for PCIeIntel ssd dc data center family for PCIe
Intel ssd dc data center family for PCIe
Low Hong Chuan
 
booting steps of a computer
booting steps of a computerbooting steps of a computer
booting steps of a computer
Anusha Babooa
 

Andere mochten auch (20)

Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
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简明教程
Python简明教程Python简明教程
Python简明教程
 
AMD Radeon R7 Series SSD
AMD Radeon R7 Series SSDAMD Radeon R7 Series SSD
AMD Radeon R7 Series SSD
 
BIOS and Secure Boot Attacks Uncovered
BIOS and Secure Boot Attacks UncoveredBIOS and Secure Boot Attacks Uncovered
BIOS and Secure Boot Attacks Uncovered
 
07. Mainboard (System Board, Motherboard)
07. Mainboard (System Board, Motherboard)07. Mainboard (System Board, Motherboard)
07. Mainboard (System Board, Motherboard)
 
Intel ssd dc data center family for PCIe
Intel ssd dc data center family for PCIeIntel ssd dc data center family for PCIe
Intel ssd dc data center family for PCIe
 
thunderbolt interface
thunderbolt interfacethunderbolt interface
thunderbolt interface
 
Booting
BootingBooting
Booting
 
Automation Testing
Automation TestingAutomation Testing
Automation Testing
 
WiGig PPT
WiGig PPTWiGig PPT
WiGig PPT
 
Moving to PCI Express based SSD with NVM Express
Moving to PCI Express based SSD with NVM ExpressMoving to PCI Express based SSD with NVM Express
Moving to PCI Express based SSD with NVM Express
 
System Booting Process overview
System Booting Process overviewSystem Booting Process overview
System Booting Process overview
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
booting steps of a computer
booting steps of a computerbooting steps of a computer
booting steps of a computer
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
AVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronicsAVR_Course_Day1 basic electronics
AVR_Course_Day1 basic electronics
 
Introduction to Motherboard
Introduction to Motherboard Introduction to Motherboard
Introduction to Motherboard
 
My Career profile
My Career profileMy Career profile
My Career profile
 

Ähnlich wie Python教程 / Python tutorial

Fabric
FabricFabric
Fabric
JS Lee
 
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
Hiroki Ohtsuka
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
Andreas Jung
 

Ähnlich wie Python教程 / Python tutorial (20)

Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Fabric
FabricFabric
Fabric
 
Python高级编程(二)
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
 
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
TypeScript와 Flow: 
자바스크립트 개발에 정적 타이핑 도입하기
 
Google Go Overview
Google Go OverviewGoogle Go Overview
Google Go Overview
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1龍華大學前端技術分享 Part1
龍華大學前端技術分享 Part1
 
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
アジャイルな開発をチームで やってみた(2010年版) - PHP Matsuri編
 
Learning Python from Data
Learning Python from DataLearning Python from Data
Learning Python from Data
 
State of Python (2010)
State of Python (2010)State of Python (2010)
State of Python (2010)
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!¡El mejor lenguaje para automatizar pruebas!
¡El mejor lenguaje para automatizar pruebas!
 
CPAN 模組二三事
CPAN 模組二三事CPAN 模組二三事
CPAN 模組二三事
 
Python programming
Python programmingPython programming
Python programming
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014
 
Intro
IntroIntro
Intro
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Overview of Python - Bsides Detroit 2012
Overview of Python - Bsides Detroit 2012Overview of Python - Bsides Detroit 2012
Overview of Python - Bsides Detroit 2012
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Python教程 / Python tutorial