Table of Contents. Preface... xxi

Similar documents
Webgurukul Programming Language Course

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

PYTHON CONTENT NOTE: Almost every task is explained with an example

Python Training. Complete Practical & Real-time Trainings. A Unit of SequelGate Innovative Technologies Pvt. Ltd.

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

About Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python

[CHAPTER] 1 INTRODUCTION 1

GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

"Charting the Course... Java Programming Language. Course Summary

CSC Advanced Scientific Computing, Fall Numpy

Python INTRODUCTION: Understanding the Open source Installation of python in Linux/windows. Understanding Interpreters * ipython.

Introduction to Python

This course is designed for anyone who needs to learn how to write programs in Python.

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Introduction. Assessment Test. Part I The Programmer s Exam 1

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

Introduction to Programming Using Java (98-388)

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

PTN-102 Python programming

Babu Madhav Institute of Information Technology, UTU 2015

Murach s Beginning Java with Eclipse

Python Scripting for Computational Science

Page 1

Supporting Materials

Python Scripting for Computational Science

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

Contents. Illustrations. 1 Introduction to Computers, the Internet, the Web and C# 1

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B

1 OBJECT-ORIENTED PROGRAMMING 1

Programming in Python 3

INTERNATIONAL INDIAN SCHOOL, RIYADH XI XII BOYS SECTION. Subject- Informatics Practices

Microsoft. Microsoft Visual C# Step by Step. John Sharp

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV

INTERNATIONAL INDIAN SCHOOL, RIYADH XI XII BOYS SECTION

Complete Python call :

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Index COPYRIGHTED MATERIAL

PYTHON. p ykos vtawynivis. Second eciitiovl. CO Ve, WESLEY J. CHUN

Course Title: Python + Django for Web Application

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

C# Programming: From Problem Analysis to Program Design. Fourth Edition

CHAPTER 1: INTRODUCING C# 3

Microsoft Visual C# Step by Step. John Sharp

ActiveNET. #202, Manjeeraa Plaza, Ameerpet, HYD

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Computer Hardware 6. The

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

Python Basics. Lecture and Lab 5 Day Course. Python Basics

Part I Basic Concepts 1

TH IRD EDITION. Python Cookbook. David Beazley and Brian K. Jones. O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Tokyo

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

PYTHON TRAINING COURSE CONTENT

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

Contents. 1 Introduction to Computers, Internet and World Wide Web 1

CERTIFICATE IN WEB PROGRAMMING

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department

The Sun s Java Certification and its Possible Role in the Joint Teaching Material

Data Structures (list, dictionary, tuples, sets, strings)

Pace University. Fundamental Concepts of CS121 1

5/23/2015. Core Java Syllabus. VikRam ShaRma

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

There are four numeric types: 1. Integers, represented as a 32 bit (or longer) quantity. Digits sequences (possibly) signed are integer literals:

Java SE 8 Programming


Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Java 1.8 Programming

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

SCIENCE. An Introduction to Python Brief History Why Python Where to use

DOT NET COURSE BROCHURE

CORE JAVA TRAINING COURSE CONTENT

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

A Web-Based Introduction

Programming in Scala Second Edition

Certification In Java Language Course Course Content

Java SE 7 Programming

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Java SE 8 Programming

JAVA CONCEPTS Early Objects

Core Java - SCJP. Q2Technologies, Rajajinagar. Course content

Java Programming with Eclipse

Java SE 8 Programming

Java Programming Training for Experienced Programmers (5 Days)

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

PTN-202: Advanced Python Programming Course Description. Course Outline

Advanced Algorithms and Computational Models (module A)

Fluent Python. Luciano Ramalho. Tokyo O'REILLY. Beijing. Sebastopol. Farnham. Boston

C ONTENTS PART I FUNDAMENTALS OF PROGRAMMING 1. and Java 3. Chapter 1 Introduction to Computers, Programs,

Object-Oriented Programming in C# (VS 2015)

Duration: Six Weeks Faculty : Mr Sai Kumar, Having 10+ Yrs Experience in IT

JAVA. Duration: 2 Months

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

A Quick Tour p. 1 Getting Started p. 1 Variables p. 3 Comments in Code p. 6 Named Constants p. 6 Unicode Characters p. 8 Flow of Control p.

Object-Oriented Programming and Data Structures

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

SELF-STUDY. Glossary

Chapters and Appendix F are PDF documents posted online at the book s Companion Website (located at

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

ABOUT CORE JAVA COURSE SCOPE:

Transcription:

Table of Contents Preface... xxi Chapter 1: Introduction to Python... 1 Python... 2 Features of Python... 3 Execution of a Python Program... 7 Viewing the Byte Code... 9 Flavors of Python... 10 Python Virtual Machine (PVM)... 11 Frozen Binaries... 12 Memory Management in Python... 12 Garbage Collection in Python... 14 Comparisons between C and Python... 15 Comparisons between Java and Python... 16 Points to Remember... 17 Chapter 2: Writing Our First Python Program... 19 Installing Python for Windows... 19 Testing the Installation in Windows 8... 23 Installing numpy... 25 Setting the Path to Python... 27 Writing Our First Python Program... 30 Executing a Python Program... 31 Using Python s Command Line Window... 31 Using Python s IDLE Graphics Window... 32 Running Directly from System Prompt... 33 Getting Help in Python... 36 Getting Python Documentation Help... 39 Reopening the Python Program in IDLE... 41 Points to Remember... 43 Chapter 3: Datatypes in Python... 45 Comments in Python... 46 Single line comments... 46 Multi line comments... 46

x Core Python Docstrings... 47 How Python Sees Variables... 49 Datatypes in Python... 51 Built-in datatypes... 51 The None Type... 51 Numeric Types... 52 Representing Binary, Octal and Hexadecimal Numbers... 53 Converting the Datatypes Explicitly... 53 bool Datatype... 55 Sequences in Python... 56 str Datatype... 56 bytes Datatype... 57 bytearray Datatype... 58 list Datatype... 59 tuple Datatype... 59 range Datatype... 60 Sets... 61 set Datatype... 61 frozenset Datatype... 62 Mapping Types... 62 Literals in Python... 63 Numeric Literals... 64 Boolean Literals... 64 String Literals... 64 Determining the Datatype of a Variable... 65 What about Characters... 66 User-defined Datatypes... 67 Constants in Python... 67 Identifiers and Reserved words... 67 Naming Conventions in Python... 68 Points to Remember... 69 Chapter 4: Operators in Python... 71 Operator... 71 Arithmetic Operators... 72 Using Python Interpreter as Calculator... 73 Assignment Operators... 73 Unary Minus Operator... 75 Relational Operators... 75

Table of Contents xi Logical Operators... 76 Boolean Operators... 77 Bitwise Operators... 78 Bitwise Complement Operator ( ~ )... 80 Bitwise AND Operator (&)... 80 Bitwise OR Operator ( )... 81 Bitwise XOR Operator ( ^ )... 81 Bitwise Left Shift Operator (<<)... 82 Bitwise Right Shift Operator (>>)... 82 Membership Operators... 84 The in Operator... 84 The not in Operator... 84 Identity Operators... 85 The is Operator... 85 The is not Operator... 86 Operator Precedence and Associativity... 87 Mathematical Functions... 88 Using IDLE Window... 91 Using Command Line Window... 92 Executing at System Prompt... 92 Points to Remember... 93 Chapter 5: Input and Output... 95 Output statements... 96 The print() Statement... 96 The print( string ) Statement... 96 The print(variables list) Statement... 97 The print(object) Statement... 98 The print( string, variables list) Statement... 98 The print(formatted string) Statement... 99 Input Statements... 101 Command Line Arguments... 108 Parsing Command Line Arguments... 110 Points to Remember... 115 Chapter 6: Control Statements... 117 Control Statements... 118 The if Statement... 118 A Word on Indentation... 119

xii Core Python The if else Statement... 121 The if elif else Statement... 122 The while Loop... 124 The for Loop... 126 Infinite Loops... 130 Nested Loops... 131 The else Suite... 136 The break Statement... 137 The continue Statement... 138 The pass Statement... 139 The assert Statement... 140 The return Statement... 141 Points to Remember... 149 Chapter 7: Arrays in Python... 151 Array... 151 Advantages of Arrays... 152 Creating an Array... 153 Importing the Array Module... 154 Indexing and Slicing on Arrays... 156 Processing the Arrays... 159 Types of Arrays... 166 Working with Arrays using numpy... 167 Creating Arrays using array()... 169 Creating Arrays using linspace... 170 Creating Arrays using logspace... 171 Creating Arrays using arange() Function... 172 Creating Arrays using zeros() and ones() Functions... 173 Mathematical Operations on Arrays... 174 Comparing Arrays... 176 Aliasing the Arrays... 179 Viewing and Copying Arrays... 180 Slicing and Indexing in numpy Arrays... 182 Dimensions of Arrays... 184 Attributes of an Array... 186 The ndim Attribute... 186 The shape Attribute... 186 The size Attribute... 187 The itemsize Attribute... 187

Table of Contents xiii The dtype Attribute... 187 The nbytes Attribute... 188 The reshape() Method... 188 The flatten() Method... 189 Working with Multi-dimensional Arrays... 189 The array() Function... 189 The ones() and zeros() Functions... 190 The eye() Function... 191 The reshape() Function... 191 Indexing in Multi-dimensional Arrays... 192 Slicing the Multi-dimensional Arrays... 194 Matrices in numpy... 196 Getting Diagonal Elements of a Matrix... 197 Finding Maximum and Minimum Elements... 198 Finding Sum and Average of Elements... 198 Products of Elements... 198 Sorting the Matrix... 199 Transpose of a Matrix... 200 Matrix Addition and Multiplication... 201 Random Numbers... 204 Points to Remember... 205 Chapter 8: Strings and Characters... 207 Creating Strings... 207 Length of a String... 209 Indexing in Strings... 209 Slicing the Strings... 211 Repeating the Strings... 213 Concatenation of Strings... 213 Checking Membership... 214 Comparing Strings... 214 Removing Spaces from a String... 215 Finding Sub Strings... 215 Counting Substrings in a String... 218 Strings are Immutable... 219 Replacing a String with another String... 221 Splitting and Joining Strings... 222 Changing Case of a String... 223 Checking Starting and Ending of a String... 224

xiv Core Python String Testing Methods... 224 Formatting the Strings... 225 Working with Characters... 228 Sorting Strings... 229 Searching in the Strings... 231 Finding Number of Characters and Words... 232 Inserting Sub String into a String... 233 Points to Remember... 235 Chapter 9: Functions... 237 Difference between a Function and a Method... 238 Defining a Function... 238 Calling a Function... 239 Returning Results from a Function... 240 Returning Multiple Values from a Function... 245 Functions are First Class Objects... 246 Pass by Object Reference... 248 Formal and Actual Arguments... 253 Positional Arguments... 253 Keyword Arguments... 254 Default Arguments... 255 Variable Length Arguments... 256 Local and Global Variables... 257 The Global Keyword... 258 Passing a Group of Elements to a Function... 260 Recursive Functions... 261 Anonymous Functions or Lambdas... 265 Using Lambdas with filter() Function... 266 Using Lambdas with map() Function... 267 Using Lambdas with reduce() Function... 269 Function Decorators... 270 Generators... 274 Structured Programming... 276 Creating our Own Modules in Python... 277 The Special Variable name... 279 Points to Remember... 280 Chapter 10: Lists and Tuples... 283 List... 283 Creating Lists using range() Function... 285

Table of Contents xv Updating the Elements of a List... 288 Concatenation of Two Lists... 290 Repetition of Lists... 291 Membership in Lists... 291 Aliasing and Cloning Lists... 291 Methods to Process Lists... 293 Finding Biggest and Smallest Elements in a List... 295 Sorting the List Elements... 296 Number of Occurrences of an Element in the List... 298 Finding Common Elements in Two Lists... 299 Storing Different Types of Data in a List... 300 Nested Lists... 301 Nested Lists as Matrices... 302 List Comprehensions... 305 Tuples... 307 Creating Tuples... 307 Accessing the Tuple Elements... 308 Basic Operations on Tuples... 310 Functions to Process Tuples... 311 Nested Tuples... 314 Inserting Elements in a Tuple... 315 Modifying Elements of a Tuple... 317 Deleting Elements from a Tuple... 318 Points to Remember... 319 Chapter 11: Dictionaries... 321 Operations on Dictionaries... 322 Dictionary Methods... 324 Using for Loop with Dictionaries... 327 Sorting the Elements of a Dictionary using Lambdas... 331 Converting Lists into Dictionary... 332 Converting Strings into Dictionary... 333 Passing Dictionaries to Functions... 334 Ordered Dictionaries... 335 Points to Remember... 336 Chapter 12: Introduction to Oops... 337 Problems in Procedure Oriented Approach... 338 Specialty of Python Language... 340 Features of Object Oriented Programming System (OOPS)... 340

xvi Core Python Classes and Objects... 340 Encapsulation... 343 Abstraction... 344 Inheritance... 347 Polymorphism... 348 Points to Remember... 349 Chapter 13: Classes and Objects... 351 Creating a Class... 351 The Self Variable... 355 Constructor... 355 Types of Variables... 357 Namespaces... 359 Types of Methods... 361 Instance Methods... 361 Class Methods... 364 Static Methods... 365 Passing Members of One Class to Another Class... 367 Inner Classes... 369 Points to Remember... 371 Chapter 14: Inheritance and Polymorphism... 373 Constructors in Inheritance... 378 Overriding Super Class Constructors and Methods... 379 The super() Method... 380 Types of Inheritance... 382 Single Inheritance... 382 Multiple Inheritance... 384 Method Resolution Order (MRO)... 388 Polymorphism... 390 Duck Typing Philosophy of Python... 391 Operator Overloading... 395 Method Overloading... 400 Method Overriding... 401 Points to Remember... 402 Chapter 15: Abstract Classes and Interfaces... 405 Abstract Method and Abstract Class... 407 Interfaces in Python... 412

Table of Contents xvii Abstract Classes vs. Interfaces... 418 Points to Remember... 419 Chapter 16: Exceptions... 421 Errors in a Python Program... 421 Compile-Time Errors... 421 Runtime Errors... 422 Logical Errors... 423 Exceptions... 425 Exception Handling... 426 Types of Exceptions... 429 The Except Block... 432 The assert Statement... 433 User-Defined Exceptions... 434 Logging the Exceptions... 436 Points to Remember... 439 Chapter 17: Files in Python... 441 Files... 441 Types of Files in Python... 442 Opening a File... 443 Closing a File... 444 Working with Text Files Containing Strings... 446 Knowing Whether a File Exists or Not... 449 Working with Binary Files... 451 The with Statement... 452 Pickle in Python... 452 The seek() and tell() Methods... 456 Random Accessing of Binary Files... 457 Random Accessing of Binary Files using mmap... 464 Zipping and Unzipping Files... 467 Working with Directories... 469 Running Other Programs from Python Program... 474 Points to Remember... 475 Chapter 18: Regular Expressions in Python... 477 Regular Expressions... 477 Sequence Characters in Regular Expressions... 483 Quantifiers in Regular Expressions... 487 Special Characters in Regular Expressions... 489

xviii Core Python Using Regular Expressions on Files... 492 Retrieving Information from a HTML File... 495 Points to Remember... 497 Chapter 19: Data Structures in Python... 499 Linked Lists... 500 Stacks... 503 Queues... 507 Deques... 510 Points to Remember... 514 Chapter 20: Date and Time... 515 The epoch... 515 Date and Time Now... 517 Combining Date and Time... 519 Formatting Dates and Times... 520 Finding Durations using timedelta... 527 Comparing Two Dates... 528 Sorting Dates... 529 Stopping Execution Temporarily... 530 Knowing the Time taken by a Program... 531 Working with Calendar Module... 532 Points to Remember... 535 Chapter 21: Threads... 537 Single Tasking... 538 Multitasking... 539 Differences between a Process and a Thread... 541 Concurrent Programming and GIL... 542 Uses of Threads... 542 Creating Threads in Python... 542 Creating a Thread without using a Class... 543 Creating a Thread by Creating a Sub Class to Thread Class... 544 Creating a Thread without Creating Sub Class to Thread Class... 546 Thread Class Methods... 547 Single Tasking using a Thread... 548 Multitasking using Multiple Threads... 549 Thread Synchronization... 553 Locks... 553 Semaphore... 555

Table of Contents xix Deadlock of Threads... 555 Avoiding Deadlocks in a Program... 557 Communication between Threads... 559 Thread Communication using nofity() and wait() Methods... 561 Thread Communication using a Queue... 563 Daemon Threads... 565 Points to Remember... 567 Chapter 22: Graphical User Interface... 569 GUI in Python... 570 The Root Window... 570 Fonts and Colors... 572 Working with Containers... 576 Canvas... 576 Frame... 584 Widgets... 586 Button Widget... 587 Arranging Widgets in the Frame... 592 Label Widget... 596 Message Widget... 597 Text Widget... 599 Scrollbar Widget... 601 Checkbutton Widget... 603 Radiobutton Widget... 605 Entry Widget... 607 Spinbox Widget... 609 Listbox Widget... 612 Menu Widget... 614 Points to Remember... 621 Chapter 23: Networking in Python... 623 Protocol... 624 TCP/IP Protocol... 624 User Datagram Protocol (UDP)... 626 Sockets... 626 Knowing IP Address... 628 URL... 628 Reading the Source Code of a Web Page... 630 Downloading a Web Page from Internet... 631 Downloading an Image from Internet... 632

xx Core Python A TCP/IP Server... 634 A TCP/IP Client... 635 A UDP Server... 637 A UDP Client... 638 File Server... 640 File Client... 641 Two-Way Communication between Server and Client... 642 Sending a Simple Mail... 644 Points to Remember... 647 Chapter 24: Python s Database Connectivity... 649 DBMS... 649 Advantages of a DBMS over Files... 649 Types of Databases Used with Python... 650 Installation of MySQL Database Software... 651 Setting the Path to MySQL Server... 661 Verifying MySQL in the Windows Operating System... 663 Installing MySQL Connector... 663 Verifying the Connector Installation... 666 Working with MySQL Database... 666 Using MySQL from Python... 668 Retrieving All Rows from a Table... 669 Inserting Rows into a Table... 672 Deleting Rows from a Table... 675 Updating Rows in a Table... 677 Creating Database Tables through Python... 678 Installation of Oracle 11g... 681 Verifying Oracle Installation in Windows Operating System... 687 Installing Oracle Database Driver... 687 Verifying the Driver Installation... 690 Working with Oracle Database... 690 Using Oracle Database from Python... 693 Stored Procedures... 695 Points to Remember... 698 Program Index... 699