Python _ Những điều Cơ Bản - Bài Giảng Khác - Trần Thanh Tùng

Đăng nhập / Đăng ký VioletBaigiang
  • ViOLET.VN
  • Bài giảng
  • Giáo án
  • Đề thi & Kiểm tra
  • Tư liệu
  • E-Learning
  • Kỹ năng CNTT
  • Trợ giúp

Thư mục

Các ý kiến mới nhất

  • TUẦN 16-BÀI 6 T3 VIẾT TÌM Ý CHO ĐOẠN VĂN...
  • TUẦN 16-BÀI 6 T2 NÓI VỀ 1 HĐ CỘNG ĐỒNG...
  • TUẦN 16-BÀI 6 T1 NGÔI NHÀ CHUNG CỦA BUÔN LÀNG...
  • TUẦN 16-BÀI 5 T4 VIẾT ĐV GT NV PHIM HOẠT...
  • TUẦN 16-BÀI 5 T3 LUYỆN TẬP VỀ ĐẠI TỪ VÀ...
  • TUẦN 16-BÀI 5 T1,2 NHỮNG LÁ THƯ...
  • TUẦN 17-BÀI 51 T2 THỤC HANH VA TRAI NGHIEM...
  • TUẦN 16-BÀI 51 T1 THỤC HANH VA TRAI NGHIEM...
  • TUẦN 16-BAI 50 EM LÀM ĐƯỢC NHỮNG GÌ...
  • TUẦN 16-BÀI 49 T2 DIEN TICH HINH TRON...
  • TUẦN 16-BÀI 49 T1 DIEN TICH HINH TRON...
  • TUẦN 16-BAI 48 T2 CHU VI HÌNH TRÒN...
  • TUẦN 15-BAI 48 T1 CHU VI HÌNH TRÒN...
  • TUẦN 15-BAI 47 ĐƯỜNG TRÒN, HÌNH TRÒN...
  • Thành viên trực tuyến

    286 khách và 81 thành viên
  • Phan Bá Phong
  • Hà Thị Thương Huế
  • ngô thị thơ
  • Hồ Thị Dung
  • Lê Thị Minh
  • Trần Thanh Hương
  • Kim Nữ Phi Vân
  • Mai Hồng Cẩm
  • Hoàng Thị Thùy Linh
  • ngô thị trung
  • Nguyễn Thị Quy
  • Hoàng Thị Lệ
  • Ánh Dương
  • Nguyễn Ánh Ngọc
  • Đinh Công Vương
  • Lê Thị Thanh Trúc
  • Hồ Ngọc Đệ
  • Nguyễn Thanh Hải
  • hùynh tiền sơn
  • Đào Văn Thắng
  • Tìm kiếm theo tiêu đề

    Searchback

    Đăng nhập

    Tên truy nhập Mật khẩu Ghi nhớ   Quên mật khẩu ĐK thành viên

    Tin tức cộng đồng

    5 điều đơn giản cha mẹ nên làm mỗi ngày để con hạnh phúc hơn

    Tìm kiếm hạnh phúc là một nhu cầu lớn và xuất hiện xuyên suốt cuộc đời mỗi con người. Tác giả người Mỹ Stephanie Harrison đã dành ra hơn 10 năm để nghiên cứu về cảm nhận hạnh phúc, bà đã hệ thống các kiến thức ấy trong cuốn New Happy. Bà Harrison khẳng định có những thói quen đơn...
  • Hà Nội công bố cấu trúc định dạng đề minh họa 7 môn thi lớp 10 năm 2025
  • 23 triệu học sinh cả nước chính thức bước vào năm học đặc biệt
  • Xem tiếp

    Tin tức thư viện

    Chức năng Dừng xem quảng cáo trên violet.vn

    12087057 Kính chào các thầy, cô! Hiện tại, kinh phí duy trì hệ thống dựa chủ yếu vào việc đặt quảng cáo trên hệ thống. Tuy nhiên, đôi khi có gây một số trở ngại đối với thầy, cô khi truy cập. Vì vậy, để thuận tiện trong việc sử dụng thư viện hệ thống đã cung cấp chức năng...
  • Khắc phục hiện tượng không xuất hiện menu Bộ công cụ Violet trên PowerPoint và Word
  • Thử nghiệm Hệ thống Kiểm tra Trực tuyến ViOLET Giai đoạn 1
  • Xem tiếp

    Hướng dẫn sử dụng thư viện

    Xác thực Thông tin thành viên trên violet.vn

    12072596 Sau khi đã đăng ký thành công và trở thành thành viên của Thư viện trực tuyến, nếu bạn muốn tạo trang riêng cho Trường, Phòng Giáo dục, Sở Giáo dục, cho cá nhân mình hay bạn muốn soạn thảo bài giảng điện tử trực tuyến bằng công cụ soạn thảo bài giảng ViOLET, bạn...
  • Bài 4: Quản lí ngân hàng câu hỏi và sinh đề có điều kiện
  • Bài 3: Tạo đề thi trắc nghiệm trực tuyến dạng chọn một đáp án đúng
  • Bài 2: Tạo cây thư mục chứa câu hỏi trắc nghiệm đồng bộ với danh mục SGK
  • Bài 1: Hướng dẫn tạo đề thi trắc nghiệm trực tuyến
  • Lấy lại Mật khẩu trên violet.vn
  • Kích hoạt tài khoản (Xác nhận thông tin liên hệ) trên violet.vn
  • Đăng ký Thành viên trên Thư viện ViOLET
  • Tạo website Thư viện Giáo dục trên violet.vn
  • Hỗ trợ trực tuyến trên violet.vn bằng Phần mềm điều khiển máy tính từ xa TeamViewer
  • Xem tiếp

    Hỗ trợ kĩ thuật

    Liên hệ quảng cáo

    Tìm kiếm Bài giảng

    Đưa bài giảng lên Gốc > Bài giảng khác >
    • Python _ Những điều cơ bản
    • Cùng tác giả
    • Lịch sử tải về

    Python _ Những điều cơ bản Download Edit-0 Delete-0

    Wait
    • Begin_button
    • Prev_button
    • Play_button
    • Stop_button
    • Next_button
    • End_button
    • 0 / 0
    • Loading_status
    Nhấn vào đây để tải về Báo tài liệu có sai sót Nhắn tin cho tác giả (Tài liệu chưa được thẩm định) Nguồn: Người gửi: Trần Thanh Tùng Ngày gửi: 23h:20' 08-07-2008 Dung lượng: 254.0 KB Số lượt tải: 56 Số lượt thích: 0 người Ha Noi University Of TechnologyInternational Training ProgrammeUnix SystemTopic PyThon Programming LanguageInstructorMr.Do Duc ThanhStudent Tran Thanh Tung*Vu Kim OanhLe Thu HongNguyen Thi ThanhWelcome To Python !What is Python?Python is an interpreted, interactive OOP languagePython is an uncomplicated and robust programming language that delivers both the power and complexity of traditional compiled languages along with the ease-of-use (and then some) of simpler scripting and interpreted languages. You`ll be amazed at how quickly you`ll pick up the language as well as what kind of things you can do with Python, not to mention the things that have already been done. Your imagination will be the only limitPython’s HistoryPython is a powerful yet easy to use programming language developed by Guido van Rossum, first released over a decade ago in 1991. With Python, you can quickly write a small project. But Python also scales up nicely and can be used for mission-critical, commercial applications. Welcome To Python !FeaturesHigh-levelObject-OrientedScalableExtensiblePortableEasy to learnEasy to readRapid Protyping ToolA memory managerRobust LanguageHaving a strong communityFree and Open SourceWelcome To Python !DrawbacksPython is not a run-time speed daemon comparedto e.g. C .– Does it matter for your application?– You can mix Python and other languages to get the best of both worldsThe dynamic typing is not trusted by static typing enthusiastsSome newbies do not like the indentation-based syntax.There is no integrated GUI support (but there are interfaces to MFC, Xlib, Athena, Motif, Qt, GTK, WxWindows, Tk and others...) Python has no compiler to native code.Welcome To Python !Installing and Running ( Fedora 8)InstallingDownload file Python-2.5.2.tarExtracting./configuremakemake installRunning PythonIt’s always installed in a standard location: usr/bin/pythonPython ScriptsPython scripts can be made executable in thesame way as shell scripts: Make the file executable : chmod +x myprog.pyAdd a suitable interpreter line at the top of the file. For portability reasons, use:#!/usr/bin/env pythonComparisonsPython Vs RubyPYTHON WINS -Ruby`s compiler/runtime error messages were mostly `syntax error` with no help. in many cases almost useless -Why does Ruby use rescue/ensure when the rest of the world has settled on try/catch/finally? I mean, its an arbitrary choice so why not follow the general convention? -Once the indentation is correct, a Python program is the cleanest looking RUBY WINS -Somewhat uneasy over Python indenting vs. Ruby explicit `end`. probably a predjudice. -Python requirement for expliciting `self` parameter to methods and instance variable access is very annoying -Ruby OO completeness is a win over Python. ComparisonsPython Vs JavaPYTHON WINS - Dynamic typing is a big productivity win for Python - The Python language itself is much simpler to code - Python is not "pure" as languages like Java. It can be integrated with Java by JyThon - Python’s Intepreter takes to initialize and takes up lots of memory.JAVA WINS -Java is way faster than Python -Java has the large portable libraries -Java has the native-code compilationGetting Help Use the on-line docs http://www.python.org/doc Read the bookCore Python ProgrammingLearning Python From Beginner To Absolute Professional.etcUse the help( ) function interactivelyPython Types We will take a look at the basic data types (and operations) available in Python before we dig into the syntax. Python uses dynamic typing:Variables refer to objects.Variables as such has no type.Objects have types (integers,float, strings, lists tuples.etc). Note : You cannot add 1 and “3”.Your First ProgramHello World >>> print "Hello INPG04" Hello INPG04Putting it in a file# hello.py print "Hello World"Variables and ExpressionsExpressionsStandard mathematical operators work like other languages:3 + 53 + (5*4)3 ** 2’Hello’ + ’World’Variable assignmenta = 4 = == != Python also provides the expression conjunction operators:and or not StringsStrings are a central data type in Python (as well as in all similar languages)Strings store 8-bit characters or bytesNull (ASCII 0) bytes are not special like in CLong strings are allowed Strings are immutable, i.e. they cannot be changed after they have been created.We can create new strings from parts of existing ones,of course.Note : Python have no character data typeStrings(Cont)Example :a = ’Hello’ # Single quotesb = “INPG04" # Double quotesc = “You said ’It was a woman.’" # A mix of bothd = ‘“ A triple quoted stringcan span multiple lineslike this’’’e = """Also works for double quotes""" Lists Lists are ordered collections of arbitrary objects Lists are not immutable, thus they can be changedin-place Like vectors (one dimensional arrays) in otherLanguages.Lists have a certain size but can grow and shrink as neededNote: No holes, though: You cannot add a fourth element to a two element list without first adding a third element. Lists ( Cont )Example :Lists of Arbitrary Objectsa = [2, 3, 4] # A list of integersb = [2, 7, 3.5, "Hello"] # A mixed listc = [] # An empty listd = [2, [a,b]] # A list containing a liste = a + b # Join two listsList Manipulationx = a[1] # Get 2nd element (0 is first)y = b[1:3] # Return a sublistz = d[1][0][TuplesTuples are like lists, but they are immutable (like strings)Literals are written using comma with parenthesis as needed: ( ) is the empty tuple (parenthesis needed!)(1,) is a tuple containing a single element (note trailing comma)(1,2) is a tuple containing two elements(1,2,) is the sameTuples(Cont)Tuplesf = (2,3,4,5) # A tuple of integersg = (,) # An empty tupleh = (2, [3,4], (10,11,12)) # A tuple containing mixed objectsTuple Manipulationx = f[1] # Element access. x = 3y = f[1:3] # Slices. y = (3,4)z = h[1][1]Lists Vs TuplesTuples are like lists, but size is fixed at time of creation.Can’t replace members (said to be "immutable")Lists and tuples (and other things) can bearbitrarily nested.Example :x=[1,[`foo`,2],(3,[4,5])]DictionariesDictionaries ( type dict) are Python`s hash table type. They work like associative arrays or hashes found in Perl and consist of key:value pairs. Keys can be almost any Python type, but are usually numbers or strings. Values, on the other hand, can be any arbitrary Python object. Dictionaries are enclosed by curly braces ( { } ). A dictionary can be indexed by any immutable type, not just integers.Dictionaries Example:>>> aDict = {} >>> aDict[`host`] = `earth` >>> aDict[`port`] = 80 >>> aDict {`host`: `earth`, `port`: 80} >>> aDict.keys() [`host`, `port`] >>> aDict[`host`] `earth` NoneNone is the only value of the type NoneType.It is used in multiple places to mean N/A, datamissing, do not care, etc.If a function does not return a value, it returnsNone implicitly. A variable containing None is not the same thing as a variable not being defined at all.Other TypesWe will not encounter the file type hereInternal types for things like functions modules classes, instances and methodseven more internal stuffTypes defined by extension modules e.g. images, database connectionsIndentationCode Blocks Use IndentationCode blocks are identified by indentation rather than using symbols like curly braces. Without extra symbols, programs are easier to read. Also, indentation clearly identifies which block of code a statement belongs to. Of course, code blocks can consist of single statements, too.StatementsPython programs consists of statements. E.g.assignments like x=10print statements to output thingsif statements for selectionwhile or for for loops Statements have no values (we cannot speak ofthe value of a print statement or an assignment)Statements have “side effects”.Statements can contain expressions (things that have a value) but can not have statements in expressions. n=n+1 (where n+1 is an expression used to calculate the value we are to assign to n)CommentsAs with most scripting and Unix-shell languages, the hash/pound ( # ) sign signals that a comment begins right from the # and continues till the end of the line.>>> # one comment >>> print `Hello INPG04!` # comment Hello INPG04! Print StatementA simple way to output data to the standardoutput is provided by the print statement:Example : >>> myString = `Hello INPG04!` >>> print myString Hello INGPG04! >>> myString ‘Hello World!’ ConditionalsThe standard if conditional statement follows this syntax: if expression: if_suite if-else if a < b: z = b else:z = aThe pass statement if a < b: pass # Do nothing else: z = aNotes:Indentation used to denote bodies.pass used to denote an empty body.There is no ’?:’ operator.Conditionals(Cont)elif statement if a == ’+’: op = PLUS elif a == ’-’: op = MINUS else: op = UNKNOWNNote: There is no switch statement.Boolean expressions: and, or, not if b >= a and b c): print "b is still between a and c"While LoopA pre-tested loop where we loop as long as thecondition is true (no loops at all if the condition isfalse the first time around):>>>x=1>>>while x >>for i in [3, 4, 10, 25]: … print i >>>for c in “tt": … print c t tLoop over a range of numbers. >>>for i in range(0,3): … print i, 1 2 3FunctionsEvery high-level language have some kind of subroutine concept. Python has functionsPython does not have procedures Functions that end without calling the return statement implicitly returns None.If we do not care about the return value from a functions, it is silently discardedFunctionsSyntax:def function_name([ arguments]): "optional documentation string“ function_suite Example :def addMe2Me(x): … `apply + operation to argument` … return (x + x) ModulesPrograms can be divided into several files. Each file defines a module. Each module has its own global namespace (there is no global namespace above all modules). Modules thus provide namespace isolation so two variables or functions with the same name in two different modules doesn`t clash.Modules enable code reusePython already provides a lot of built-in modules for us to use.Modules(cont)To get access to a module, we use the import statement:Example: >>> import sys >>> import string >>> sys.platform `win32` We can imports modulesfrom the same directory as the running program.from a directory on the python module path. After the import, we can refer to global variables, functions etc in module by using “module_name” before the their name.Example: sys.platformExceptions Python handles errors and other exceptional occurrences by raising exceptions.If not caught, they will cause the program to be aborted. >>> a=1/0; print “not reached” Traceback (most recent call last): File "", line 1, in ? ZeroDivisionError: integer division or modulo by zero>>>Exceptions(cont)Exceptions are caught by placing the “dangerous” code in a try:-except: compound statement try:f = open(“name’’) except IOError: print "Couldn’t open ‘name’. Sorry."ClassesA class is merely a container for static data members or function declarations, called a class`s attributes.Declaring a Class class class_name[( base_classes_if_any)]: "optional documentation string" static_member_declarations method_declarations Python LibraryPython is packaged with a large library of standard modulesString processingOperating system interfacesNetworkingThreadsGUIDatabaseLanguage servicesSecurity.And there are many third party modulesXMLNumeric ProcessingPlotting/SummaryKnown what Python is.Had a overview of Python Known how to program in at least one other program language.Hope you will practice Python programming soon You can absorb a lot of stuff, forget about the details, but remember that you can look them upin the bookson-lineCompleted Thanks for Not Falling Asleep ! ^( = ^ . ^ = )^   ↓ ↓ Gửi ý kiến

    Hãy thử nhiều lựa chọn khác

  • Thumbnailtoán lop2
  • ThumbnailTHUYẾT TRÌNH VĂN 9
  • ThumbnailHÁI HOA DÂN CHỦ
  • ThumbnailThuyết trình giải pháp hội thi sáng tạo ... thuật Giáo viên.
  • ThumbnailTOÁN BÌNH MINH-Tiết 17. Làm quen với tỉ số
  • ThumbnailBáo cáo biện pháp nâng cao chất lượng ... dạy lớp 5
  • Còn nữa... ©2008-2017 Thư viện trực tuyến ViOLET Đơn vị chủ quản: Công ty Cổ phần Mạng giáo dục Bạch Kim - ĐT: 04.66745632 Giấy phép mạng xã hội số 16/GXN-TTĐT cấp ngày 13 tháng 2 năm 2012

    Từ khóa » Slide Bài Giảng Python