Python is a great programming language. It is a complete tutorial of using this programming language.
This slides is split into two parts, and it is the second part. Another part is at: http://www.slideshare.net/moskytw/programming-with-python-basic.
Learn python in easy steps. This presentation will cover followings
1. Python basics
2. How to write a python code
3. Variable usage & their syntax
4. Strings handling
5. Files handling
6. How to use loops and others.
7. Python Vs C language.
This document provides an introduction and overview of the Python programming language. It covers Python's history and key features such as being object-oriented, dynamically typed, batteries included, and focusing on readability. It also discusses Python's syntax, types, operators, control flow, functions, classes, imports, error handling, documentation tools, and popular frameworks/IDEs. The document is intended to give readers a high-level understanding of Python.
( ** Python Certification Training: https://www.edureka.co/python ** )
This Edureka PPT on Advanced Python tutorial covers all the important aspects of using Python for advanced use-cases and purposes. It establishes all of the concepts like system programming , shell programming, pipes and forking to show how wide of a spectrum Python offers to the developers.
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
This document contains slides from a Python workshop presentation. It introduces Python, discussing its history, philosophy, features, and how to write Python code. Some key points covered include:
- Python was created in the late 1980s and named after Monty Python.
- It aims to have clear, readable syntax while also being powerful.
- Python code tends to be more concise than languages like Java and C++.
- It uses indentation rather than braces to define code blocks.
- Common data types like lists, dictionaries, and tuples are covered.
- Basic programming constructs like conditionals, loops, functions and file I/O are demonstrated.
The document discusses an agenda for a Python workshop that will cover topics such as an introduction to Python, its features, how it is used in enterprises, installing Python on Windows and Linux, setting up development environments, and learning about Python concepts like strings, numbers, functions, modules, data structures, object-oriented programming, and errors/exceptions handling. The workshop will also include hands-on exercises and a quiz.
The speaker discussed the benefits of type hints in Python. Type hints allow specifying the expected types of function parameters and return values, improving code readability, enabling code completion in editors, and allowing static type checking tools to analyze the code for type errors. The speaker demonstrated how to write type hints according to PEP 484 and PEP 526 standards and how to retrieve type information. Tools like Mypy were presented for doing static type analysis to catch errors. Using type hints and type checkers in continuous integration was recommended to catch errors early when collaborating on projects. The speaker concluded by explaining how using type hints made it easier for their team to port code from Python 2 to Python 3.
Python Programming - XIII. GUI ProgrammingRanel Padon
The document discusses Tkinter, the Python GUI programming interface. Tkinter provides a wrapper for the Tk GUI toolkit. Tk was originally created for Tcl but has bindings for other languages like Python through Tkinter. Tkinter allows Python programs to create graphical user interfaces by providing classes and methods that interface with the Tk GUI toolkit. Some key Tkinter widgets discussed include Frame, Label, Button, Entry, Radiobutton and Checkbutton. Pros of Tkinter include brevity, cross-platform support, maturity and extensibility. Potential cons are that it relies on Tcl/Tk which some consider unnecessary and it may have a theoretical speed disadvantage due to the multiple layers of interpretation.
Python is an interpreted, object-oriented programming language created by Guido van Rossum in 1990. It has a clear, readable syntax and is designed to be highly extensible. Python code is often much shorter than equivalent code in other languages like C++ or Java due to features like indentation-based blocks and dynamic typing. It is used for web development, scientific computing, and more.
What is Python? An overview of Python for science.Nicholas Pringle
Python is a general purpose, high-level, free and open-source programming language that is readable and intuitive. It has strong scientific computing packages like NumPy, SciPy, and Matplotlib that allow it to be used for tasks like MATLAB. Python emphasizes code readability and reusability through standards like PEP8 and version control, making it well-suited for collaboration between individual, institutional, and developer users in its large, diverse community.
Writing Fast Code (JP) - PyCon JP 2015Younggun Kim
The document discusses optimizing Python code performance through profiling. It introduces various profiling tools like cProfile and line_profiler. As an example, it profiles a "fibonachicken" function that uses Fibonacci numbers to calculate the number of chickens needed to serve a given number of people. Profiling reveals the fib() and is_fibonacci() functions as bottlenecks. The document suggests improving fib() with Binet's formula and is_fibonacci() with Gessel's formula to avoid using fib() and gain better performance.
The document provides an overview of the Python programming language. It discusses that Python is an easy to learn, high-level, open-source programming language. It describes Python's design philosophy of code readability and how it allows programmers to express concepts in fewer lines of code compared to languages like C++ and Java. The document also discusses Python's powerful libraries, wide use across industries, and how to get started with Python programming using the IDLE integrated development environment.
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
This document provides an overview of a Python Foundation course that introduces Python concepts and programming style. The course covers Python history and culture, multi-paradigm programming in Python including procedural, modular, scripting, object-oriented and functional styles. It also covers Python syntax, logic and flow control, built-in data types, classes and objects. The course includes coding experiments, programming labs and homework assignments.
Python is a general purpose programming language created by Guido van Rossum in 1991. It is widely used by companies like Google, Facebook, and Dropbox for tasks like web development, data analysis, and machine learning. Python code is easy to read and write for beginners due to its simple syntax and readability. It supports features like object oriented programming, procedural programming, and functional programming.
The document provides an overview of the Python programming language. It discusses that Python is an interpreted, interactive, object-oriented language created by Guido van Rossum in the late 1980s. It describes Python as high-level, portable, and has an extensive standard library. The document then covers Python variables and data types, basic operators, and provides examples of Python code, including defining variables, strings, lists, tuples, and dictionaries.
Introduction to go language programming , benchmark with another language programming nodejs , php , ruby & python . how install go . use what IDE . and rapid learnin golang
This document provides an introduction and overview of the Python programming language. It discusses what Python is, why to learn a scripting language and why Python specifically. It covers how to install Python and how to edit Python code using IDLE. The rest of the document demonstrates various Python concepts like variables, data types, operators, flow control statements, functions and more through sample code examples. Each code example is accompanied by instructions to run the sample script in IDLE.
Python Programming Course Lecture by IoT Code Lab Training.
Discussed Topic:
Chapter 0: Python Overview
0. Python Introduction
1. What is Python?
2. Story of Python
3. Why Python
4. Use of Python
5. Python Download + Installation
6. How to Use? + Online Course Resource
1. Variable, Data Type, Expression
1. Create First Python Program File
2. First Program - Hello World
3. Comment
4. Variable + Data Type + Example
5. Variable Naming Convention
6. Practice 0.1
2. Input/ Output
1. Input/ Output (String)
1. A String Input & Output
2. Display A Message in Print & Input function
3. Check Data Type
4. Practice 0.2
2. Input/ Output (Number)
1. An Integer Number Input & Output + Check Data Type
2. Type Conversion
3. A Float Number Input & Output + Check Data Type
4. Built-in Function with Example
5. Practice 0.3
3. Formatted Input Output
This deck was used to conduct a hands-on workshop at Mumbai Tech Meetup. It covers an introduction to Go, core language features, Object Oriented features of Go, Concurrency, API Servers and more.
This document discusses programming languages, compilers vs interpreters, and introduces Python. It explains that a programming language communicates instructions to a machine and can be used to create programs. An interpreter reads and executes code directly, while a compiler converts source code into machine code. Python is an interpreted, object-oriented language that is easy to learn yet powerful. It can be used for web, enterprise, and other applications. The document also provides basic information on Python syntax and data types.
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Introduction To Python' will help you establish a strong hold on all the fundamentals in the Python programming language. Below are the topics covered in this PPT:
Introduction To Python
Keywords And Identifiers
Variables And Data Types
Operators
Loops In Python
Functions
Classes And Objects
OOPS Concepts
File Handling
YouTube Video: https://youtu.be/uYjRzbP5aZs
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
The document provides an introduction to Python programming by discussing statements and syntax. It covers assignment statements, expression statements, print operations, conditional statements like if/else, and loop statements like while and for. It explains how Python programs are composed of modules containing statements with expressions. Truth tests for conditionals and built-in functions like range, zip that can be used in loops are also overviewed.
(1) Python uses indentation rather than braces to indicate blocks of code for functions and control flow. All statements within a block must be indented the same amount.
(2) Python identifiers can consist of letters, numbers, and underscores but must start with a letter or underscore. Identifiers are case-sensitive.
(3) There are reserved words in Python that cannot be used as identifiers such as def, if, else, and, or, not, etc.
Python offers several tool and public services that simplify starting and maintaining an open source project. This presentation show cases some of the most helpful one and explains the process, beginning with an empty folder and finishing with a published PyPI package.
This document provides an introduction to programming in Go. It discusses the origins and intentions of the Go language, where it is commonly used today, and what Go is and isn't. Go was created to be a systems programming language with better productivity than C++. It has seen widespread adoption beyond its original use cases. While Go isn't a functional or object-oriented language, it is compiled, statically typed, memory managed, concurrent, and ideal for building cloud infrastructure. The document also covers Go syntax including variables, types, loops, conditionals, functions, and more.
The document provides an introduction and overview of the Python programming language. It discusses that Python is an interpreted, object-oriented, high-level programming language that is easy to learn and read. It also covers Python features such as portability, extensive standard libraries, and support for functional, structured, and object-oriented programming. The document then discusses Python data types including numbers, strings, and various Python syntax elements before concluding with the history and evolution of the Python language through various versions.
It is the slides for SITCON[1] 2013 Workshop[2]: "Git - The Version Control System You Must Know".
[1]: http://sitcon.org/
[2]: http://www.openfoundry.org/tw/activities/details/415-the-open-source-way-coder
In your code base, to understand a random line, how many lines do you need to read back? Cloud you make it zero?
This talk will start with the impact of the maintainability, define the maintainability as “to understand a random line, the lines you need to read back”, show the practicing techniques to make it zero, or nearly zero, and finally, reach the goal: boost the maintainability.
It's the revision of “Beyond the Style Guides” [1] and the talk at PyCon TW 2016 [2], PyCon APAC/KR 2016 [3], and GDG DevFest Taipei 2016 [4].
[1]: https://speakerdeck.com/mosky/beyond-the-style-guides
[2]: https://tw.pycon.org/2016
[3]: https://www.pycon.kr/2016apac/
[4]: https://devfest-taipei-3cbee.firebaseapp.com/
This document provides an overview of sockets programming in Python. It discusses:
1) The basic Python sockets modules (Socket and SocketServer) which provide low-level networking and simplified server development.
2) Examples of creating stream and datagram sockets, binding addresses, listening for connections, and accepting clients.
3) How the SocketServer module simplifies creating TCP servers with a basic "Hello World" example server.
It's a talk about how to write understandable code from understanding human brain at Taipei.py [1] and PyCon HK 2015 [2].
[1]: http://www.meetup.com/Taipei-py/events/222174472/
[2]: http://2015.pycon.hk/
Python is an interpreted, object-oriented programming language created by Guido van Rossum in 1990. It has a clear, readable syntax and is designed to be highly extensible. Python code is often much shorter than equivalent code in other languages like C++ or Java due to features like indentation-based blocks and dynamic typing. It is used for web development, scientific computing, and more.
What is Python? An overview of Python for science.Nicholas Pringle
Python is a general purpose, high-level, free and open-source programming language that is readable and intuitive. It has strong scientific computing packages like NumPy, SciPy, and Matplotlib that allow it to be used for tasks like MATLAB. Python emphasizes code readability and reusability through standards like PEP8 and version control, making it well-suited for collaboration between individual, institutional, and developer users in its large, diverse community.
Writing Fast Code (JP) - PyCon JP 2015Younggun Kim
The document discusses optimizing Python code performance through profiling. It introduces various profiling tools like cProfile and line_profiler. As an example, it profiles a "fibonachicken" function that uses Fibonacci numbers to calculate the number of chickens needed to serve a given number of people. Profiling reveals the fib() and is_fibonacci() functions as bottlenecks. The document suggests improving fib() with Binet's formula and is_fibonacci() with Gessel's formula to avoid using fib() and gain better performance.
The document provides an overview of the Python programming language. It discusses that Python is an easy to learn, high-level, open-source programming language. It describes Python's design philosophy of code readability and how it allows programmers to express concepts in fewer lines of code compared to languages like C++ and Java. The document also discusses Python's powerful libraries, wide use across industries, and how to get started with Python programming using the IDLE integrated development environment.
Python Foundation – A programmer's introduction to Python concepts & styleKevlin Henney
This document provides an overview of a Python Foundation course that introduces Python concepts and programming style. The course covers Python history and culture, multi-paradigm programming in Python including procedural, modular, scripting, object-oriented and functional styles. It also covers Python syntax, logic and flow control, built-in data types, classes and objects. The course includes coding experiments, programming labs and homework assignments.
Python is a general purpose programming language created by Guido van Rossum in 1991. It is widely used by companies like Google, Facebook, and Dropbox for tasks like web development, data analysis, and machine learning. Python code is easy to read and write for beginners due to its simple syntax and readability. It supports features like object oriented programming, procedural programming, and functional programming.
The document provides an overview of the Python programming language. It discusses that Python is an interpreted, interactive, object-oriented language created by Guido van Rossum in the late 1980s. It describes Python as high-level, portable, and has an extensive standard library. The document then covers Python variables and data types, basic operators, and provides examples of Python code, including defining variables, strings, lists, tuples, and dictionaries.
Introduction to go language programming , benchmark with another language programming nodejs , php , ruby & python . how install go . use what IDE . and rapid learnin golang
This document provides an introduction and overview of the Python programming language. It discusses what Python is, why to learn a scripting language and why Python specifically. It covers how to install Python and how to edit Python code using IDLE. The rest of the document demonstrates various Python concepts like variables, data types, operators, flow control statements, functions and more through sample code examples. Each code example is accompanied by instructions to run the sample script in IDLE.
Python Programming Course Lecture by IoT Code Lab Training.
Discussed Topic:
Chapter 0: Python Overview
0. Python Introduction
1. What is Python?
2. Story of Python
3. Why Python
4. Use of Python
5. Python Download + Installation
6. How to Use? + Online Course Resource
1. Variable, Data Type, Expression
1. Create First Python Program File
2. First Program - Hello World
3. Comment
4. Variable + Data Type + Example
5. Variable Naming Convention
6. Practice 0.1
2. Input/ Output
1. Input/ Output (String)
1. A String Input & Output
2. Display A Message in Print & Input function
3. Check Data Type
4. Practice 0.2
2. Input/ Output (Number)
1. An Integer Number Input & Output + Check Data Type
2. Type Conversion
3. A Float Number Input & Output + Check Data Type
4. Built-in Function with Example
5. Practice 0.3
3. Formatted Input Output
This deck was used to conduct a hands-on workshop at Mumbai Tech Meetup. It covers an introduction to Go, core language features, Object Oriented features of Go, Concurrency, API Servers and more.
This document discusses programming languages, compilers vs interpreters, and introduces Python. It explains that a programming language communicates instructions to a machine and can be used to create programs. An interpreter reads and executes code directly, while a compiler converts source code into machine code. Python is an interpreted, object-oriented language that is easy to learn yet powerful. It can be used for web, enterprise, and other applications. The document also provides basic information on Python syntax and data types.
** Python Certification Training: https://www.edureka.co/python **
This Edureka PPT on 'Introduction To Python' will help you establish a strong hold on all the fundamentals in the Python programming language. Below are the topics covered in this PPT:
Introduction To Python
Keywords And Identifiers
Variables And Data Types
Operators
Loops In Python
Functions
Classes And Objects
OOPS Concepts
File Handling
YouTube Video: https://youtu.be/uYjRzbP5aZs
Python Tutorial Playlist: https://goo.gl/WsBpKe
Blog Series: http://bit.ly/2sqmP4s
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
The document provides an introduction to Python programming by discussing statements and syntax. It covers assignment statements, expression statements, print operations, conditional statements like if/else, and loop statements like while and for. It explains how Python programs are composed of modules containing statements with expressions. Truth tests for conditionals and built-in functions like range, zip that can be used in loops are also overviewed.
(1) Python uses indentation rather than braces to indicate blocks of code for functions and control flow. All statements within a block must be indented the same amount.
(2) Python identifiers can consist of letters, numbers, and underscores but must start with a letter or underscore. Identifiers are case-sensitive.
(3) There are reserved words in Python that cannot be used as identifiers such as def, if, else, and, or, not, etc.
Python offers several tool and public services that simplify starting and maintaining an open source project. This presentation show cases some of the most helpful one and explains the process, beginning with an empty folder and finishing with a published PyPI package.
This document provides an introduction to programming in Go. It discusses the origins and intentions of the Go language, where it is commonly used today, and what Go is and isn't. Go was created to be a systems programming language with better productivity than C++. It has seen widespread adoption beyond its original use cases. While Go isn't a functional or object-oriented language, it is compiled, statically typed, memory managed, concurrent, and ideal for building cloud infrastructure. The document also covers Go syntax including variables, types, loops, conditionals, functions, and more.
The document provides an introduction and overview of the Python programming language. It discusses that Python is an interpreted, object-oriented, high-level programming language that is easy to learn and read. It also covers Python features such as portability, extensive standard libraries, and support for functional, structured, and object-oriented programming. The document then discusses Python data types including numbers, strings, and various Python syntax elements before concluding with the history and evolution of the Python language through various versions.
It is the slides for SITCON[1] 2013 Workshop[2]: "Git - The Version Control System You Must Know".
[1]: http://sitcon.org/
[2]: http://www.openfoundry.org/tw/activities/details/415-the-open-source-way-coder
In your code base, to understand a random line, how many lines do you need to read back? Cloud you make it zero?
This talk will start with the impact of the maintainability, define the maintainability as “to understand a random line, the lines you need to read back”, show the practicing techniques to make it zero, or nearly zero, and finally, reach the goal: boost the maintainability.
It's the revision of “Beyond the Style Guides” [1] and the talk at PyCon TW 2016 [2], PyCon APAC/KR 2016 [3], and GDG DevFest Taipei 2016 [4].
[1]: https://speakerdeck.com/mosky/beyond-the-style-guides
[2]: https://tw.pycon.org/2016
[3]: https://www.pycon.kr/2016apac/
[4]: https://devfest-taipei-3cbee.firebaseapp.com/
This document provides an overview of sockets programming in Python. It discusses:
1) The basic Python sockets modules (Socket and SocketServer) which provide low-level networking and simplified server development.
2) Examples of creating stream and datagram sockets, binding addresses, listening for connections, and accepting clients.
3) How the SocketServer module simplifies creating TCP servers with a basic "Hello World" example server.
It's a talk about how to write understandable code from understanding human brain at Taipei.py [1] and PyCon HK 2015 [2].
[1]: http://www.meetup.com/Taipei-py/events/222174472/
[2]: http://2015.pycon.hk/
This document discusses using Python to connect to and interact with a PostgreSQL database. It covers:
- Popular Python database drivers for PostgreSQL, including Psycopg which is the most full-featured.
- The basics of connecting to a database, executing queries, and fetching results using the DB-API standard. This includes passing parameters, handling different data types, and error handling.
- Additional Psycopg features like server-side cursors, transaction handling, and custom connection factories to access columns by name rather than number.
In summary, it provides an overview of using Python with PostgreSQL for both basic and advanced database operations from the Python side.
It is the slides for COSCUP[1] 2013 Hands-on[2], "Learning Python from Data".
It aims for using examples to show the world of Python. Hope it will help you with learning Python.
[1] COSCUP: http://coscup.org/
[2] COSCUP Hands-on: http://registrano.com/events/coscup-2013-hands-on-mosky
This document discusses functional programming in Python. It begins by defining functional programming and some of its key concepts like immutable data, functions as first-class citizens, and recursion. It then shows how Python supports functional programming with features like first-class functions, lambda expressions, and built-in functions like map, filter and reduce. Finally, it discusses other functional programming techniques in Python like partial function application, currying, and tail call optimization, while noting some of Python's limitations for functional programming like its non-pure nature and lack of pattern matching.
The basics of Python are rather straightforward. In a few minutes you can learn most of the syntax. There are some gotchas along the way that might appear tricky. This talk is meant to bring programmers up to speed with Python. They should be able to read and write Python.
This document discusses the Go programming language and why it has become popular. It notes that Go is an optional language released in 2012 that does not force developers to use it for certain applications like Java does for Android. The document states that the one main reason Go has become popular is that "It just works" - Go makes development simpler by handling things like concurrency and deployment automatically while still exposing lower-level functionality. It recommends using Go for distributed systems, portable command line tools, and situations where team productivity is important.
It is mainly about the multithreading and the multiprocessing in Python, and *in Python's flavor*.
It's also the share at Taipei.py [1].
[1] http://www.meetup.com/Taipei-py/events/220452029/
Clime is a Python library which lets you convert any module into a multi-command CLI program without any configuration.
It is a short tour of Clime.
The full documentation of Clime: http://clime.mosky.tw/.
This document discusses WordPress widgets and how they can be used to customize themes. Widgets allow modification of function and appearance and are configurable code snippets. Not all themes support widgets. Widgets can be added by dragging them from the available list onto widget areas. Common widgets include Archives, Categories, Links, and Text, which provide navigation, background content, and functionality. Widgets must have relevant content to be useful.
Automating and Accelerating Application Deployments to IBM WebSphere without ...XebiaLabs
Slides from the Jun 11, 2013 Global WebSphere Community webinar "Deploy. Faster. Automating and Accelerating Application Deployments to IBM WebSphere without Scripting"
ZIPCodeTW: Find Taiwan ZIP Code by Address FuzzilyMosky Liu
It was a lightning talk at PyCon APAC 2014 [1]. It introduces the tool to find ZIP code, ZIPCodeTW [2].
[1] http://tw.pycon.org/2014apac/
[2] http://zipcode.mosky.tw
It was the talk, titled "Graph-Tool: The Efficient Network Analyzing Tool for Python", at PyCon APAC 2014 [1] and PyCon SG 2014 [2]. It introduces you to Graph-Tool by mass code snippets.
[1] https://tw.pycon.org/2014apac
[2] https://pycon.sg/
Intro to Python Workshop San Diego, CA (January 19, 2013)Kendall
These slides were presented at the Intro to Python Workshop in San Diego, California on January 19, 2013. This workshop was for absolute beginners in Python, and builds from the ground up. There were two projectors used in the presentation, one for showing these slides and one with a command-line Python prompt to show the execution of example code throughout the presentation.
The presenters were David Neiss and Kendall Chuang of the San Diego Python Users Group.
This document provides an overview and introduction to the Python programming language. It begins with background on the author and a brief history of Python's development. Key details about Python include that it is a high-level, general-purpose programming language designed to be readable. Python finds widespread use in fields like web development, science, and system administration. The document concludes with an introduction to basic Python concepts like indentation, conditionals, modules and built-in help functions.
The PyConTW (http://tw.pycon.org) organizer wishes to improve the quality and quantity of the programming cummunities in Taiwan. Though Python is their core tool and methodology, they know it's worth to learn and communicate with wide-ranging communities. Understanding cultures and ecosystem of a language takes me about three to six months. This six-hour course wraps up what I - an experienced Java developer - have learned from Python ecosystem and the agenda of the past PyConTW.
你可以在以下鏈結找到中文內容:
http://www.codedata.com.tw/python/python-tutorial-the-1st-class-1-preface
This document provides an introduction to the Python programming language. It begins by asking why Python is needed after showing a simple "Hello World" program in C versus Python. Python is then described as a dynamic, open source language designed for simplicity and productivity. Key features of Python like its interpreter-based nature, clear syntax, portability, large standard library, and suitability for many types of applications are outlined. The document demonstrates basic Python concepts like indentation, lack of variable typing, input/output, comments, and popular Python environments. It concludes by providing references to learn more about Python and announcing an upcoming PyCon conference.
Python is a popular programming language created by Guido van Rossum in 1991. It is easy to use, powerful, and versatile, making it suitable for beginners and experts alike. Python code can be written and executed in the browser using Google Colab, which provides a Jupyter notebook environment and access to computing resources like GPUs. The document then discusses installing Python using Anaconda, basic Python concepts like indentation, variables, strings, conditionals, and loops.
Anton Kasyanov, Introduction to Python, Lecture1Anton Kasyanov
Anton Kasyanov will be giving a weekly introduction to Python lecture on Wednesdays at 4:15pm. He wants to share his knowledge of Python and improve students' English. Python is a high-level programming language that is easy to read and supports multiple paradigms. It has automatic memory management and is cross-platform. Major companies like Google use Python for web development, databases, GUIs, and more.
This document provides an introduction to the Python programming language. It defines Python as a high-level, general-purpose and interpreted programming language. It then discusses that Python is easy to learn, can be used for a wide range of applications, and code is interpreted line by line at runtime. The document also covers why Python is a useful language due to its productivity, popularity within industries, ease of learning, large ecosystem of libraries, and ability to run on multiple platforms. It concludes by explaining basic Python concepts like variables, strings, numbers and data types.
Python is a popular, high-level programming language used for web development, software development, data science, and more. It can be used to build both simple scripting programs as well as large-scale applications. Key characteristics of Python include being dynamically typed, having automatic memory management, and using indentation to define code blocks rather than curly braces. Python supports procedural, object-oriented, and functional programming styles and has a large standard library.
This document provides an overview of the Python programming language. It discusses that Python is an interpreted, high-level, general-purpose programming language created by Guido van Rossum in 1991. It is commonly used for web development, software development, data science, and more. The document then covers Python syntax, basic programming concepts like variables and data types, and how to set up a Python environment and write simple Python programs.
4_Introduction to Python Programming.pptxGnanesh12
This document provides an introduction to Python programming. It discusses the fundamentals of computing and problem solving, including algorithms and pseudocodes. It then describes the history and development of the Python programming language. Key features of Python like being easy to learn, cross-platform, and having a large standard library are outlined. Different modes of running Python like interactive and script modes are explained. Finally, it covers basic Python concepts like data types, values, variables, and statements.
The document provides an introduction to the Python programming language. It discusses the history and overview of Python, including that it is an interpreted, interactive, and object-oriented scripting language. It then covers Python features such as being easy to learn and read, having a broad standard library, and being portable. The document also demonstrates basic Python concepts like data types, variables, conditional statements, and functions.
[FREE PDF sample] Programming Python with CD 2nd Edition Mark Lutz ebooksraginmoradtx
Immediate Programming Python with CD 2nd Edition Mark Lutz download after payment at https://ebookfinal.com/download/programming-python-with-cd-2nd-edition-mark-lutz. Explore additional textbooks and ebooks in https://ebookfinal.com Full chapter PDF available.
This document provides an overview of the Python programming language, including its history, key features, and common uses. It discusses how Python is an interpreted, object-oriented language with dynamic typing and automatic memory management. Examples are given of Python's syntax for numbers, strings, modules, data structures like lists and dictionaries, and the interactive shell. Popular applications of Python like web development, science, and games are also mentioned.
This document provides an introduction to the Python programming language. It discusses what Python is, its history and creator, why it is popular, who uses it, and how to get started with the syntax. Key topics covered include Python's readability, dynamic typing, standard library, and use across many industries. The document also includes code examples demonstrating basic Python concepts like variables, strings, control flow, functions, and file input/output.
Get Programming Python with CD 2nd Edition Mark Lutz free all chaptersgricharnasg5
Instant download Programming Python with CD 2nd Edition Mark Lutz after payment at https://ebookfinal.com/download/programming-python-with-cd-2nd-edition-mark-lutz. Discover more textbooks or ebooks in https://ebookfinal.com Download full chapter PDF.
Python is a high-level, general-purpose programming language that is easy to learn and widely used. It can be used for both procedural and object-oriented programming. Python code is executed by the Python interpreter rather than being compiled into machine code. It supports multiple programming paradigms like procedural, object-oriented, and functional programming. Common uses of Python include web development, data analysis, scientific computing, and software testing.
This document provides an overview of statistical regression analysis with Python. It discusses defining assumptions, validating assumptions with a dataset on extramarital affairs, performing correlation analysis, estimating models using ordinary least squares, understanding regression results including interaction effects, handling categorical variables, and addressing outliers. Modeling techniques covered include linear, logistic, and quantile regression as well as robust linear regression.
The document provides examples of how Python is used in different domains such as websites, desktop applications, science, embedded systems, and more. It also discusses why Python is popular due to its readability, ease of learning, rich libraries, and ability to be sped up with tools like Numba and Cython. The document outlines topics for learning Python including primitives, control flow with if/while statements, composites like lists and dictionaries, and for loops. It recommends keeping learning through tutorials, documentation, and communities.
This document provides an introduction to data science with Python. It discusses key concepts in data science including visualization, statistics, machine learning, deep learning, and big data. Various Python packages are introduced for working with data, including Jupyter, NumPy, SciPy, Matplotlib, Pandas, Scikit-learn and others. The document outlines the main steps in a data science analysis process, including defining assumptions, validating assumptions with data, and iterating. Specific techniques are covered like preprocessing, dimensionality reduction, statistical modeling, and machine learning modeling. The document emphasizes an iterative approach to learning through applying concepts to problems and data.
This document discusses hypothesis testing in Python. It covers simulating and analyzing test datasets, how hypothesis tests work, common statistical tests like t-tests and chi-squared tests, and steps for completing a hypothesis test. Key points include defining the null and alternative hypotheses, estimating error rates from a confusion matrix, determining necessary sample sizes based on desired alpha and beta levels, and fully reporting test results. Other statistical analyses like correlation and regression are also briefly mentioned. Overall the document provides an introduction to performing and interpreting hypothesis tests in Python.
Writing concurrent program is hard; maintaining concurrent program even is a nightmare. Actually, a pattern which helps us to write good concurrent code is available, that is, using “channels” to communicate.
This talk will share the channel concept with common libraries, like threading and multiprocessing, to make concurrent code elegant.
It's the talk at PyCon TW 2017 [1] and PyCon APAC/MY 2017 [2].
[1]: https://tw.pycon.org/2017
[2]: https://pycon.my/pycon-apac-2017-program-schedule/
The document outlines Mosky's background as a Python engineer and speaker who works on the Python packages MoSQL and Clime. It then provides an overview of Mosky discussing topics like the Git workflow, invoice system, and seller dashboard used behind the scenes at Pinkoi. Specific instructions are given on branching, committing, pushing, reviewing, and merging code as part of the recommended Git workflow.
MoSQL: More than SQL, but Less than ORM @ PyCon APAC 2013Mosky Liu
It is the slides of the talk, "MoSQL: More than SQL, but Less than ORM", at PyCon APAC 2013. It introduces MoSQL after v0.6.
About MoSQL:
MoSQL is a Python library which lets you use common Python’s data structures to build SQLs.
http://mosql.mosky.tw/
** Please visit https://speakerdeck.com/mosky/mosql-more-than-sql-but-less-than-orm-at-pycon-apac-2013 for the newer slide. :)
It is the slides of the talk, "MoSQL: More than SQL, but Less than ORM", at PyCon TW 2013.
About MoSQL:
MoSQL is a Python library which lets you use common Python’s data structures to build SQLs, and provides a convenient model of result set.
http://mosql.mosky.tw/
GDG Douglas - Google AI Agents: Your Next Intern?felipeceotto
Presentation done at the GDG Douglas event for June 2025.
A first look at Google's new Agent Development Kit.
Agent Development Kit is a new open-source framework from Google designed to simplify the full stack end-to-end development of agents and multi-agent systems.
Plooma is a writing platform to plan, write, and shape books your wayPlooma
Plooma is your all in one writing companion, designed to support authors at every twist and turn of the book creation journey. Whether you're sketching out your story's blueprint, breathing life into characters, or crafting chapters, Plooma provides a seamless space to organize all your ideas and materials without the overwhelm. Its intuitive interface makes building rich narratives and immersive worlds feel effortless.
Packed with powerful story and character organization tools, Plooma lets you track character development and manage world building details with ease. When it’s time to write, the distraction-free mode offers a clean, minimal environment to help you dive deep and write consistently. Plus, built-in editing tools catch grammar slips and style quirks in real-time, polishing your story so you don’t have to juggle multiple apps.
What really sets Plooma apart is its smart AI assistant - analyzing chapters for continuity, helping you generate character portraits, and flagging inconsistencies to keep your story tight and cohesive. This clever support saves you time and builds confidence, especially during those complex, detail packed projects.
Getting started is simple: outline your story’s structure and key characters with Plooma’s user-friendly planning tools, then write your chapters in the focused editor, using analytics to shape your words. Throughout your journey, Plooma’s AI offers helpful feedback and suggestions, guiding you toward a polished, well-crafted book ready to share with the world.
With Plooma by your side, you get a powerful toolkit that simplifies the creative process, boosts your productivity, and elevates your writing - making the path from idea to finished book smoother, more fun, and totally doable.
Get Started here: https://www.plooma.ink/
A brief introduction to OpenTelemetry, with a practical example of auto-instrumenting a Java web application with the Grafana stack (Loki, Grafana, Tempo, and Mimir).
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...Insurance Tech Services
A modern Policy Administration System streamlines workflows and integrates with core systems to boost speed, accuracy, and customer satisfaction across the policy lifecycle. Visit https://www.damcogroup.com/insurance/policy-administration-systems for more details!
Artificial Intelligence Applications Across IndustriesSandeepKS52
Artificial Intelligence is a rapidly growing field that influences many aspects of modern life, including transportation, healthcare, and finance. Understanding the basics of AI provides insight into how machines can learn and make decisions, which is essential for grasping its applications in various industries. In the automotive sector, AI enhances vehicle safety and efficiency through advanced technologies like self-driving systems and predictive maintenance. Similarly, in healthcare, AI plays a crucial role in diagnosing diseases and personalizing treatment plans, while in financial services, it helps in fraud detection and risk management. By exploring these themes, a clearer picture of AI's transformative impact on society emerges, highlighting both its potential benefits and challenges.
Invited Talk at RAISE 2025: Requirements engineering for AI-powered SoftwarE Workshop co-located with ICSE, the IEEE/ACM International Conference on Software Engineering.
Abstract: Foundation Models (FMs) have shown remarkable capabilities in various natural language tasks. However, their ability to accurately capture stakeholder requirements remains a significant challenge for using FMs for software development. This paper introduces a novel approach that leverages an FM-powered multi-agent system called AlignMind to address this issue. By having a cognitive architecture that enhances FMs with Theory-of-Mind capabilities, our approach considers the mental states and perspectives of software makers. This allows our solution to iteratively clarify the beliefs, desires, and intentions of stakeholders, translating these into a set of refined requirements and a corresponding actionable natural language workflow in the often-overlooked requirements refinement phase of software engineering, which is crucial after initial elicitation. Through a multifaceted evaluation covering 150 diverse use cases, we demonstrate that our approach can accurately capture the intents and requirements of stakeholders, articulating them as both specifications and a step-by-step plan of action. Our findings suggest that the potential for significant improvements in the software development process justifies these investments. Our work lays the groundwork for future innovation in building intent-first development environments, where software makers can seamlessly collaborate with AIs to create software that truly meets their needs.
Integrating Survey123 and R&H Data Using FMESafe Software
West Virginia Department of Transportation (WVDOT) actively engages in several field data collection initiatives using Collector and Survey 123. A critical component for effective asset management and enhanced analytical capabilities is the integration of Geographic Information System (GIS) data with Linear Referencing System (LRS) data. Currently, RouteID and Measures are not captured in Survey 123. However, we can bridge this gap through FME Flow automation. When a survey is submitted through Survey 123 for ArcGIS Portal (10.8.1), it triggers FME Flow automation. This process uses a customized workbench that interacts with a modified version of Esri's Geometry to Measure API. The result is a JSON response that includes RouteID and Measures, which are then applied to the feature service record.
Generative Artificial Intelligence and its ApplicationsSandeepKS52
The exploration of generative AI begins with an overview of its fundamental concepts, highlighting how these technologies create new content and ideas by learning from existing data. Following this, the focus shifts to the processes involved in training and fine-tuning models, which are essential for enhancing their performance and ensuring they meet specific needs. Finally, the importance of responsible AI practices is emphasized, addressing ethical considerations and the impact of AI on society, which are crucial for developing systems that are not only effective but also beneficial and fair.
Build Smarter, Deliver Faster with Choreo - An AI Native Internal Developer P...WSO2
Enterprises must deliver intelligent, cloud native applications quickly—without compromising governance or scalability. This session explores how an internal developer platform increases productivity via AI for code and accelerates AI-native app delivery via code for AI. Learn practical techniques for embedding AI in the software lifecycle, automating governance with AI agents, and applying a cell-based architecture for modularity and scalability. Real-world examples and proven patterns will illustrate how to simplify delivery, enhance developer productivity, and drive measurable outcomes.
Learn more: https://wso2.com/choreo
14 Years of Developing nCine - An Open Source 2D Game FrameworkAngelo Theodorou
A 14-year journey developing nCine, an open-source 2D game framework.
This talk covers its origins, the challenges of staying motivated over the long term, and the hurdles of open-sourcing a personal project while working in the game industry.
Along the way, it’s packed with juicy technical pills to whet the appetite of the most curious developers.
Key AI Technologies Used by Indian Artificial Intelligence CompaniesMypcot Infotech
Indian tech firms are rapidly adopting advanced tools like machine learning, natural language processing, and computer vision to drive innovation. These key AI technologies enable smarter automation, data analysis, and decision-making. Leading developments are shaping the future of digital transformation among top artificial intelligence companies in India.
For more information please visit here https://www.mypcot.com/artificial-intelligence
Have you upgraded your application from Qt 5 to Qt 6? If so, your QML modules might still be stuck in the old Qt 5 style—technically compatible, but far from optimal. Qt 6 introduces a modernized approach to QML modules that offers better integration with CMake, enhanced maintainability, and significant productivity gains.
In this webinar, we’ll walk you through the benefits of adopting Qt 6 style QML modules and show you how to make the transition. You'll learn how to leverage the new module system to reduce boilerplate, simplify builds, and modernize your application architecture. Whether you're planning a full migration or just exploring what's new, this session will help you get the most out of your move to Qt 6.
In a tight labor market and tighter economy, PMOs and resource managers must ensure that every team member is focused on the highest-value work. This session explores how AI reshapes resource planning and empowers organizations to forecast capacity, prevent burnout, and balance workloads more effectively, even with shrinking teams.
Insurance policy management software transforms complex, manual insurance operations into streamlined, efficient digital workflows, enhancing productivity, accuracy, customer service, and profitability for insurers. Visit https://www.damcogroup.com/insurance/policy-management-software for more details!
The Future of Open Source Reporting Best Alternatives to Jaspersoft.pdfVarsha Nayak
In recent years, organizations have increasingly sought robust open source alternative to Jasper Reports as the landscape of open-source reporting tools rapidly evolves. While Jaspersoft has been a longstanding choice for generating complex business intelligence and analytics reports, factors such as licensing changes and growing demands for flexibility have prompted many businesses to explore other options. Among the most notable alternatives to Jaspersoft, Helical Insight stands out for its powerful open-source architecture, intuitive analytics, and dynamic dashboard capabilities. Designed to be both flexible and budget-friendly, Helical Insight empowers users with advanced features—such as in-memory reporting, extensive data source integration, and customizable visualizations—making it an ideal solution for organizations seeking a modern, scalable reporting platform. This article explores the future of open-source reporting and highlights why Helical Insight and other emerging tools are redefining the standards for business intelligence solutions.
2. Mosky:
● The examples and the PDF version are available at:
– j.mp/mosky-programming-with-python.
● It is welcome to give me any advice of this slide or
ask me the answers of the challenges.
– mosky.tw
2
5. Topics
● Basic Topics ● Adv. Topics
– Python 2 or 3? – Module and Package
– Environment – Typing
– hello.py – Comprehension
– Common Types – Functional Technique
– Flow Control – Object-oriented Prog.
– File I/O – Useful Libraries
– Documentation ● Final Project
– Scope – A Blog System
5
6. An Investigation
Do you know _________ ?
– any other programming language
– Object-oriented
– Static Typing; Strong and Weak Typing
– Dynamic Typing
– Functor; Closure
– Functional Programming
– Web development
6
8. Python 2 or 3?
● Python 2.x ● Python 3.x
– status quo – present & future
– 2.7 is end-of-life release – under active development
– harder for newcomers – easier for newcomers
– more third-party lib. – less third-party lib.
– 2to3.py – 3to2.py
– backported features: – new features:
● What's News in Python 2.6 ● What's News in Python 3.0
docs.python.org/release/2.6.4/whatsnew/2.6.html docs.python.org/py3k/whatsnew/3.0.html
● What's News in Python 2.7
docs.python.org/dev/whatsnew/2.7.html
8
9. Python 2 or 3? (cont.)
● Use Python 3 if you can.
● Decide Python 2 or 3 by the libraries you will use.
● Today, we will go ahead with Python 2.
And introduce you to the changes in Python3.
9
11. On Linux or Mac
● Python is built-in on Linux or Mac.
● All you have to do is check the version.
Type "python" in any terminal.
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license"
for more information.
>>>
11
12. On Windows
● Download the installer from:
"http://python.org/download"
● Install it.
● Add the Python's PATH.
– Computer → System Properties → Advanced system
settings → Advanced tab → Environment Variables →
System Variables → find PATH.
– "...;C:Python27"
12
13. Editor / IDE
● The Editors ● The IDE
– Sublime Text 2 – IDLE
www.sublimetext.com
● Debian-base:
– VIM sudo apt-get install idle
wiki.python.org/moin/Vim ● Windows:
– Gnome Text Editor Use the Start Menu to
(gedit) search "IDLE"
– Notepad++
● The others:
notepad-plus-plus.org – wiki.python.org/moin/PythonEditors
– ...
13
14. The Python Shell
● Type "python" in terminal.
– >>>
– ...
● Leaving a shell:
– exit()
– Linux or Mac: Ctrl+D
– Windows: Ctrl+Z<Enter>
14
15. The python Command
● Enter Python shell without arguments.
● python hello.py
● python -c 'print "Hello, World!"'
● python -m SimpleHTTPServer
15
17. hello.py
#!/usr/bin/env python
● #! the shebang.
# -*- coding: utf-8 -*- ● # -*- defines the encoding
# file: hello.py of this file.
● # means the comments.
def hello(name=None):
if name:n ● : starts a block.
return 'Hello, %s!' %
name
else: ● A block uses 4-space indent.
return 'Hello, Python!' ● A statement ends with n.
17
18. hello.py (cont.)
if __name__ == '__main__':
● __name__, the name of
module.
import sys
if len(sys.argv) >= 2: ● import is important.
print The usage:
hello(sys.argv[1])
else:
● import sys
print hello() ● from sys import argv
● … as alias
18
20. The print Statement
print 'End with a new line char.'
print 'Print', 'multiple', 'strings.'
print 'End with a space.',
print # print a new line char
20
21. The print function in Python 3
print('End with a new line char.')
print('Print', 'multiple', 'strings.')
print('End with a space.', end=' ')
print() # print a new line char
print('End with a space.', end='')
print('a', 'b', 'c', seq=',')
21
37. List and Tuple
List (mutable seq.) Tuple (seq.)
– [] – tuple()
– ['item'] – ('item', )
– ['s', 100, u'unicode'] – ('s', 100, u'unicode')
– list('abc') – tuple('abc')
– 'a b c'.split(' ')
– 'n'.join(['spam', – 'n'.join(('spam',
'eggs']) 'eggs'))
– x, y = [1, 2] – x, y = (1, 2)
– x, y = [y, x] – x, y = (y, x)
37
38. Sequence
Sequence Mutable Seq.
– s[i] = x
– x in s # performance? – s[i:j] = t
– x not in s – del s[i:j]
– s + t – s[i:j:k] = t
– s * n, n * s – s.append(x)
– s.insert(i, x)
– s[i] – s.pop([i])
– s[i:j] – s.remove(x) # performance?
– s[i:j:k] – s.extend(t)
in-place
– len(s)
– s.sort([cmp[, key[, reverse]]])
– s.index(x) – s.sort([key[, reverse]]) # Py 3
– s.count(x) – s.reverse()
38
41. Sequence (cont.)
Slicing and Slice object:
– s = range(10) – s = 'I am a str.'
– t = s – s[:-3]
– t[0] = 'A'
– print s – s.reverse()
– t is s → TypeError
– s[::-1]
– t = s[:] – ''.join(reversed(s))
– t is s
– slice(None, None, -1)
41
42. Mapping
Dict. (mutable map.)
– len(d)
– {}
– d[k]
– {'A ': 1, 'B': 2, 'C': 3} – d[k] = v
– dict({...}) – del d[k]
– dict(A=1, B=2, C=3) – k in d, k not in d
– d.copy()
– d.get(key[, default])
– k = 'ABC' – d.setdefault(key[, default])
– v = [1, 2, 3] – d.items(), d.keys(), d.values()
– pairs = zip(k, v) – d.pop(key[, default)
– dict(pairs) – d.update([other])
...
42
43. Set
Set (mutable set)
– len(s)
– set() – x in s, x not in s
– {'A', 'B', 'C'} # Py3 – s.copy()
– s.add(elem)
– set('ABC') – s.discard(elem)
– set(['A','B','C']) – s.pop()
– s |= other
– s &= other
– s | other | ...
– s & other & ...
– s < | <= | == | > = | > other
...
43
45. The if Statement
if [condition 1]:
…
elif [condition 2]:
…
elif [condition 3]:
…
else:
…
[exp. if true] if [condition] else [exp. if false]
45
46. Truth Value Testing
They are same as False in a boolean context:
– None
– False
– Zeros (ex. 0, 0.0, 0L, 0j)
– Empty containers (ex. '', [], {})
– __nonzero__() or __len__() returns 0 or False
46
47. Truth Value Testing (cont.)
● if not None: ...
● if not []: ...
● if [0]: ...
● if [[]]: ...
● if "": ...
● if {}: ...
● if not {0: False}: …
…
47
48. The for Statement
for [item] in [iterable]: for i in [0, 1, 2]:
… print i
for i in range(3): for i in xrange(3):
print i print i
48
49. The for Statement in Python 3
for [item] in [iterable]: for i in [0, 1, 2]:
… print i
for i in range(3): for i in xrange(3):
print i print i
49
50. The for Statement (cont.)
for i in range(1, 3): for i in range(3, -1, -1):
print i print i
s = [1, 2, 3] s = [...]
t = 'xyz' for i, item in enumerate(s):
print i, item
for i, j in zip(s, t):
print i, j
50
51. The for Statement (cont.)
● It is like for … each in other language.
– Note: Python hasn't other for loop.
● It can iterate all of iterable object.
– In other words, the object which defined __iter__.
– ex. sequence, mapping, set, ...
51
52. Challenge 1: A Pyramid
● Use for loop to build a *
pyramid on right. ***
– without limit. *****
– limit: in two lines *******
● hint: string formatting
52
53. Challenge 2-1: Count the Chars
● Use for loop to count "Please count the
the sentence on right. characters here."
– without limit.
– limit: without if
● hint: use get
{'P': 1, ...}
53
54. Challenge 2-2: Collect the Chars
● Use for loop to collect "Here are UPPERCASE
the chars. and lowercase chars."
– limit: use setdefault
{'c': ['C', 'c',
'c'], ...}
54
55. The while Statement
tasks = [...]
while tasks: while 1:
… …
● It leaves the loop once ● A infinite loop.
the tasks is empty. ● It is better to use block
mechanism in a loop.
– ex. I/O block
55
56. The break, continue Statement
loop …: loop …:
if …: break if …: continue
● It terminates a loop. ● It continues with the
next iteration.
56
57. The break, continue Statement (cont.)
● They do the same thing in both C and Python.
● Using break or continue is encouraged.
– take the place of the complicated condition in a while.
– faster, because Python is interpreted.
● Just use them.
57
59. The else Clause on Loops
loop …:
…
else:
…
● No a clause on the if statement!
● If the loop isn't broken by any break statement, the
else block is executed.
● It replaces the flags we usually used.
59
60. Challenge 3-1: The Primes
● Try to filter the primes [2, 3, 5, 7, 11, 13,
from [2, 100). 17, 19, 23, 29, 31,
37, 41, 43, 47, 53,
– without limit. 59, 61, 67, 71, 73,
– limit: use loop's else 79, 83, 89, 97]
60
62. The try Statement in Python 3
try:
…
except LookupError as e:
…
except (IndexError, KeyError) as e:
…
else:
…
finally:
…
62
63. The try Statement (cont.)
● For avoiding to catch the exception we don't expect, you should:
– reduce your code in try block.
●
move them to else block.
– make the exception precise in except statement.
● Avoid using Exception.
● ref: docs.python.org/2/library/exceptions.html#exception-hierarchy
● Release the resource in finally block.
– or use context manager
– ex. file, socket, …
● raise SomeError
63
69. The def Statement (cont.)
def f(): pass
def g(): pass
d = {'x': f, 'y': g}
d['x']()
● Python functions are first-class functions.
– It means you can pass functions as arguments, and
assign functions to variables.
– It is like the function pointers in C.
69
70. An Example of Using while, try and def.
# file: ex_try.py $ python ex_try.py
def take_int(prompt='Give me a int: '):
Give me a int: str
while 1:
try:
It is not a int!
user_input = int(raw_input(prompt)) Give me a int: abc
except ValueError, e:
print 'It is not a int!' It is not a int!
else:
return user_input Give me a int: 100
if __name__ == '__main__':
I got a int from user:
x = take_int() 100
print 'I got a int from user: %d' % x
$
70
71. A Trap of the Default Value
# file: ex_defval_trap.py ● Because the list is
created when the
def f(items=[]): function is defined.
items.append(1)
return items
● Avoid to use the
mutable types as the
if __name__ == '__main__': default value.
print f() # -> [1]
print f() # -> [1, 1]
print f() # -> [1, 1, 1]
71
72. Challenge 4: A BMI Calculator
● BMI: Body Mass Index Enter your height (M):
– BMI = weight (KG) ÷ height (M)2 1.63
– < 18.5 → Underweight
Enter your weight (KG):
– [18.5, 25) → Normal weight
– [25, 30) → Overweight 49
– >= 30 → Obesity ---
● Write a BMI calculator.
Your BMI is:
– without limit.
– limit: only one if
18.44 (Underweight)
● hint: use loop Ideal weight is between:
49.15 ~ 66.42
72
74. The file Object
f = open('input.txt') f =
print f.read() open('output.txt',
'w')
f.seek(0)
f.write('a line.n')
for line in f:
f.close()
print line,
f.close()
74
75. The Context Manager
with open('input.txt') as f:
for line in f:
print line,
f.close()
● Python 2.5↑
– Python 2.5.x: from __future__ import with_statement
– Python 2.6↑: It is mandatory.
75
76. Challenge 2: Count the Chars (cont.)
– limit 3: with the files The path of input:
input.txt
The path of output:
output.txt
---
The result was
written.
76
77. The csv Moudle
#!/usr/bin/env python 1, apple
# -*- coding: utf-8 -*- 2, orange
# file: ex_csv.py
3, watermelon
import csv
['1', ' apple']
with open('ex_csv.csv') as f:
['2', ' orange']
for row in csv.reader(f):
print row ['3', ' watermelon']
77
78. The os.path Moudle
# file: ex_os_path.py $ python ex_os_path.py
from os import walk
from os.path import join
It requires a path as
def list_files(path):
paths = []
argument.
for root, dir_names, file_names in walk(path):
for file_name in file_names:
paths.append(join(root, file_name))
$ python ex_os_path.py .
return paths
…/1
if __name__ == '__main__':
import sys
…/b/4
from os.path import abspath, dirname
if len(sys.argv) == 2:
…/a/2
path = abspath(dirname(sys.argv[1]))
for path in list_files(path): …/a/3
print path
else:
print 'It requires a path as argument.'
78
80. The help Function
● In Python shell: ● In terminal:
– help(open) – $ pydoc SimpleHTTPServer
– dir(open) – $ pydoc csv
– $ pydoc os.path
– 'n'.join(dir(open))
80
81. Your Documentation
$ pydoc ex_doc
# file: ex_doc.py Help on module ex_doc:
'''module-level doc.''' NAME
ex_doc - module-level doc.
def f(x): FILE
'''A short sentence describes
this function. /home/mosky/programming-with-python/ex_doc.py
FUNCTIONS
About the parameters, return f(x)
value or any other detail ... A short sentence describes this
''' function.
pass
About the parameters, return value or
any other detail ...
81
83. Scope
# file: ex_scope.py $ python ex_scope.py
global
x = 'global'
local
def f():
$
if 1:
x = 'local'
return x
● Scopes are decided by
functions.
if __name__ == '__main__':
print x
print f()
83
84. The LEGB Rule
# file: ex_LEGB.py ● return …
global_var = 100 – Local (in function)
def f():
enclosed_var = 10
– Enclosed
def g():
– Global
local_var = 1
return sum([local_var, enclosed_var,
– Built-in
global_var])
return g()
if __name__ == '__main__':
print f() # -> 111
84
86. Challenge 5: Mix All
● You have many $ python mix.py pyramid 10
functions now. …
$ python mix.py primes 100
Try to write a CLI
…
program to trigger your
$ python mix.py bmi 1.63 49
functions.
…
– without limit
$ python mix.py blah blah
– limit: without if. Please check your args.
86