Introduction to python 20110917
-
Upload
aiti-education -
Category
Education
-
view
708 -
download
3
Transcript of Introduction to python 20110917
Giới thiệu ngôn ngữ lập trình Python
Hoàng Nam Hả[email protected]
5’ tự giới thiệu
Hoàng Nam Hải
• Master of Art in Business IT
• Coder/programmer: 17 năm
• Mobile application: 2 năm
• Founder & CEO của công ty
ManaTech (mana.vn)
• Chuyên sâu trong 3 lĩnh vực:
• Web Crawler
• P2P streaming
• J2ME application
• Language: Java 2năm, Python 2 năm,
C#6 năm , Vb.Net, Perl, Pascal ...
Ứng dụng Sóng VàngCung cấp thông tin dịch vụ, địa điểm thay thế cho cuốn danh bạ Những trang vàng.
Ngôn ngữ lập trình: C++Chạy trên các thiết bị sử dụng hệ điều hành SamSung Bada
Giải nhì cuộc thi lập trình Bada
Cổng thông tin OneApp cho Android
• Ngôn ngữ lập trình: Java• Chạy tốt với các thiết bị
Android cấu hình thấp
Ứng dụng Zing Me clientTruy cập nhiều tiện ích trên mạng xã hội Zing Me.
Ưu điểm của phần mềm: • Giao diện thân thiện• Tốc độ cao• Chi phí kết nối
(3G/GPRS) thấp• Tính năng đa dạng
• Ngôn ngữ lập trình: Java/J2ME
Ứng dụng World Cup 2010
Cung cấp mọi thông tin xoay quanh World Cup 2010: tin tức, lịch thi đấu, bảng xếp hạng, tường thuật trận đấu...
• Ngôn ngữ lập trình: Java/J2ME
• Chạy tốt trên các dòng máy điện thoại cấu hình thấp
5’ Khán giả tự giới thiệu
• Python, Java, C#, C++...• PHP, Javascript, Flash ...• Json, XML, CSS, Web service,
Html ...
Ngôn ngữ lập trình Python
1. Why?2. Tour? (Cưỡi ngựa xem
hoa)3. How to begin?
Why Python?Why not Java? C#? C++? PHP? ...Why not SQL? Oracle? ...
Why? Why? Why?
For fun For $,$
Dễ họcCấu trúc, cú pháp đơn giản
Thư viện nhiều, chất lượng tốtjson, http, xml, zlibimap, pop3, snmp, sqlite, mysqltwisted, django, cherrypy ...
Đa năngServer: Web app, chat server, mail
server, monitor service, các app tích hợp dịch vụ,
Client: Phần mềm GUI, nghiên cứu dữ liệu...
Code một tí là chạy được...
FreeĐa hệHiệu năng cao (high-perf)
Network, memory, serialize/deserializeHiệu quả cao
productivity, maintain, deploy
Ai dùng Python?Dự án nào dùng Python?
Web site: Google, Google App Engine, Youtube, Google Web search....System: NASA, IBM, HP, Intel, Cisco...Desktop: Dropbox, Miro playerMobile phone: Nokia, Microsoft (Windows CE)P2P: Bittorrent
Tour – Cưỡi ngựa xem hoa
http://python.org
http://docs.python.org
x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print y
1.Whitespace2.Multiple assignment3.Document string4.Sequence types, list comprehension5.Functions: define, default value,
order of args, used as data type6.Json, Send mail, Twisted, Cherrypy
Whitespace
Whitespace is meaningful in Python: especially indentation and placement of newlines.
• Use a newline to end a line of code. – Use \ when must go to next line prematurely.
• No braces { } to mark blocks of code in Python… Use consistent indentation instead. – The first line with less indentation is outside of the
block.– The first line with more indentation starts a nested
block
• Often a colon appears at the start of a new block. (E.g. for function and class definitions.)
Comment & document
• Start comments with # – the rest of line is ignored.• Can include a “documentation string” as the first line of any
new function or class that you define.• The development environment, debugger, and other tools
use it: it’s good style to include one.
def my_function(x, y): “““This is the docstring. This
function does blah blah blah.”””# The code would go here...
Multiple Assignment
• Một lúc có thể gán nhiều giá trị• Một hàm có thể trả về nhiều giá trị
Xử lý danh sách: dễ & nhanh
Xử lý danh sách: dễ & nhanh (2)
Xử lý danh sách: dễ & nhanh (3)
Xử lý danh sách: dễ & nhanh (4)
Dùng Function như một object
Download và cài đặt thư viện
Easy install
Example 1. Install a package by name, searching PyPI for the latest version, and automatically downloading, building, and installing it:easy_install SQLObject
Example 2. Install or upgrade a package by name and version by finding links on a given "download page":easy_install -f http://pythonpaste.org/package_index.html SQLObject
Example 3. Download a source distribution from a specified URL, automatically building and installing it:easy_install http://example.com/path/to/MyPackage-1.2.3.tgz
JSON
Gmail Send
Tài liệu tự học