Python, developed by Guido van Rossum of Netherlands in the late 80s, and named after the BBC TV show Monty Python's Flying Circus, is one of the most user-friendly and powerful general-purpose computer programming languages available today. Its English-like syntax makes it a great language for teaching and learning computer programming. Python’s powerful data structures/types such as lists, tuples, dictionaries, sets, and arrays make coding simple. It also comes with an extensive collection of built-in/library functions that allows users to develop software applications with relative ease. Besides, users can freely import external modules to help them develop all sorts of applications. Python’s interactive and interpreted mode makes coding and testing software easy. Python also doubles us as a powerful and sophisticated calculator. You can use Python to develop all sorts of applications ranging from simple Mathematical and Text processing to Database, Web, Graphical User Interface, Network, Games, Data Mining, Artificial Intelligence, Machine Learning and Deep Learning.
This book is intended for beginners who have little or no knowledge of programming. It is also suitable for intermediate programmers who already have some knowledge of programming. This text is suitable for secondary school, college and university students irrespective of their field of study – be it Arts, Business, Science, Engineering, Life Sciences or Medicine. It starts with the basics, but progresses rapidly to the advanced topics such as lists, tuples, dictionaries, arrays, functions, classes, files and databases. So whether you are a beginner or an intermediate programmer, this book will help you master the essentials of Python programming very quickly. The book is written in a simple, easy-to-read style and contains numerous examples to illustrate the programming concepts presented. It also contains exercises to test the reader’s grasp of the material presented in each chapter.
Table of Contents
1. About Python
1.1 Python Features
1.2 Python Environment
1.3 Installing Python on Windows
1.4 Running Python Code
1.5 Sample Runs
1.6 Parts of a Python Program
2. Python Basics
2.1 Identifiers
2.2 Keywords
2.3 Variables
2.4 Comments
2.5 Quotes
2.6 Blank Lines and Indentation
2.7 Multiline Statements
2.8 Operators
2.9 Expressions
2.10 Assignment Statements
2.11 Multiple Assignments in Single Statements
2.12 Multiple Statements on Single Lines
2.13 Code Blocks
2.14 Data Types
2.15 Input-Output Statements
2.16 Importing Modules
3. Control Structures
3.1 Sequence
3.2 Decision Making
3.3 Loops
3.4 Other Control Flows
3.5 Sample Programs
4. Advanced Data Types
4.1 Lists
4.2 Tuples
4.3 Dictionaries
4.4 Sets
4.5 Arrays
5. Advanced Input/Output
5.1 Reading Data from Keyboard
5.2 Sending Output to Monitor
5.3 Formatting Output
5.4 Reading Input from Text File
5.5 Writing Output to Text File
5.6 Reading from and Writing to Text Files
5.7 Sending Output to Printer
6. Built-in Functions
6.1 What are Functions?
6.2 Built-in Functions
6.3 Math Functions
6.4 String Functions
6.5 Data Conversion Functions
6.6 Input/Output Functions
6.7 Date Functions
6.8 List Functions
6.9 Tuple Functions
6.10 Dictionary Functions
6.11 Set Functions
6.12 Sample Programs
7. User-defined Functions
7.1 Why User-defined Functions?
7.2 Defining Functions
7.3 Calling Functions
7.4 Call by Reference vs. Value
7.5 Function Overloading
7.6 Scope of Variables
7.7 Recursive Functions
7.8 Anonymous Functions
7.9 Sample Programs
8. Classes
8.1 Object-oriented Concepts
8.2 Defining Classes
8.3 Class Inheritance
8.4 Abstract Classes
8.5 Overloading and Overriding Methods
8.6 Operator Overloading
8.7 Object Interaction
8.8 Sample programs
9. Threading
9.1 What are Threads?
9.2 Importing Thread Modules
9.3 Thread Methods
9.4 Creating Threads With Functions
9.5 Creating Threads With Classes
9.6 Synchronizing Threads
9.7 Accessing Shared Resources
9.8 Daemon vs. Non-Daemon Threads
9.9 Enumerating Threads
9.10 Sample Programs
10. Database
10.1 What is a Database?
10.2 Database Concepts
10.3 SQL Commands
10.4 Creating Database
10.5 Inserting Records
10.6 Fetching Records
10.7 Displaying Records in Different Formats
10.8 Inserting Records from Lists
10.9 Deleting Records
10.10 Updating Records
10.11 Aggregate Functions
10.12 Multiple Databases
10.13 MySQL Database
Objectives and Topics
This book aims to provide a comprehensive, hands-on introduction to Python programming for beginners and intermediate learners, covering everything from basic syntax to advanced topics like object-oriented programming, threading, and database management through practical, executable examples.
- Python fundamentals (identifiers, variables, control structures, and data types)
- Input/Output handling, including text file processing and formatting
- Comprehensive coverage of built-in and user-defined functions
- Object-oriented programming concepts and class implementation
- Advanced computing topics including threading, synchronization, and database interaction
Excerpt from the Book
1.6 Parts of a Python Program
A Python program has many parts/sections (see the below sample program): comments, expressions, statements, input, output, functions, import, etc. We will explain the different parts of a Python program using a simple sample program given below.
Note: The line numberings on the left, generated by the system, is for reference purpose only – they are not part of the code. Also, for easy reading, Python uses different colors for different parts of a program: green for comments, blue for keywords, pink for functions, etc.
Comments
Inserting comments in a program makes the code more readable. You can insert comments on a single line, on several lines, or inline after a statement.
A single line comment starts with a sharp character (#) as in lines 7, 10…. in the sample code. Everything on that after # is treated as a comment. You can create a multiline comment by starting each line with a #.
An inline comment starts with a # after a statement as in lines 12, 17…. in the sample code.
You can also insert a multiline comment by starting and ending the comment with triple apostrophes ('''). Such a comment can span several lines as in lines 2 to 6.
Line spacing
Inserting blank lines to separate code blocks makes a program more readable as in lines 9, 14….
Indentation
Code blocks in Python are indented by a fixed number of spaces (typically 4 spaces) as in lines 12 and 13. All statements in the code block must follow the same indentation.
Summary of Chapters
Chapter 1: Introduction to Python, covering basic installation, execution modes, and core program structure.
Chapter 2: Foundations of Python programming including identifiers, variables, operators, and basic data types.
Chapter 3: Essential control flow structures, including sequence, decision making (if/else), and loops.
Chapter 4: In-depth guide to advanced data structures like lists, tuples, dictionaries, sets, and arrays.
Chapter 5: Detailed techniques for input and output operations including file handling and data formatting.
Chapter 6: Overview of Python's built-in and library functions for math, strings, and data conversion.
Chapter 7: Concepts of user-defined functions, including recursion, overloading, and scope.
Chapter 8: Object-oriented programming implementation, classes, inheritance, and operator overloading.
Chapter 9: Technical aspects of threading, synchronization, and managing shared resources in Python.
Chapter 10: Practical database management using SQL within Python environments.
Keywords
Python, Programming, Control Structures, Data Types, Input/Output, Functions, Recursion, Object-oriented Programming, Classes, Inheritance, Threading, Synchronization, Database, SQLite, SQL Commands
Frequently Asked Questions
What is the primary focus of this book?
The book focuses on teaching Python programming by using numerous practical, executable examples to help both beginners and intermediate learners master essential programming concepts.
Who is this book intended for?
It is designed for beginners with little to no programming experience, but also serves as a suitable resource for intermediate programmers looking to reinforce their knowledge of Python.
What is the main objective of the author?
The primary goal is to guide students from the very basics of Python to advanced functionalities like threading and database integration through a simple, easy-to-read style.
Which programming methodologies are covered?
The text covers procedural programming basics, functional programming concepts, and comprehensive object-oriented programming techniques.
How is the subject matter organized in the main chapters?
The book is structured into logical building blocks starting from language fundamentals, moving through data structures and functions, and concluding with complex applications like threading and databases.
What makes this book a good learning tool?
Each chapter is enriched with learning outcomes, numerous illustrative code examples, and exercises designed to test the reader's grasp of the material provided.
How does the author explain the difference between a function and a method in Python?
The author distinguishes them by noting that a method is typically attached to a class or object and uses dot notation, whereas a function is defined independently.
How is thread synchronization handled in the provided material?
The book demonstrates thread synchronization through mechanisms such as threading.Lock objects, Event objects, and Condition objects for managing shared resources.
- Quote paper
- Palaniappan Sellappan (Author), 2018, Learn Python. The Easy Way, Munich, GRIN Verlag, https://www.grin.com/document/435037