Python is an amazing programming language. It can be applied to almost any programming task. It allows for rapid development and debugging. Getting started with Python is like learning any new skill: it’s important to find a resource you connect with to guide your learning. Luckily, there’s no shortage of excellent books that can help you learn both the basic concepts of programming and the specifics of programming in Python. With the abundance of resources, it can be difficult to identify which book would be best for your situation. Python for Beginners is a concise single point of reference for all material on python.
• Provides concise, need-to-know information on Python types and statements, special method names, built-in functions and exceptions, commonly used standard library modules, and other prominent Python tools
• Offers practical advice for each major area of development with both Python 3.x and Python 2.x
• Based on the latest research in cognitive science and learning theory
• Helps the reader learn how to write effective, idiomatic Python code by leveraging its best―and possibly most neglected―features
This book focuses on enthusiastic research aspirants who work on scripting languages for automating the modules and tools, development of web applications, handling big data, complex calculations, workflow creation, rapid prototyping, and other software development purposes. It also targets graduates, postgraduates in computer science, information technology, academicians, practitioners, and research scholars.
Author(s): Kuldeep Singh Kaswan, Jagjit Singh Dhatterwal, B. Balamurugan
Publisher: CRC Press/Chapman & Hall
Year: 2023
Language: English
Pages: 442
City: Boca Raton
Cover
Half Title
Title Page
Copyright Page
Table of Contents
Preface
Editor Biographies
Chapter 1: Introduction to Python
1.1 Introduction
1.2 Software
1.3 Development Tools
1.3.1 Advanced Python Tools
1.3.2 Web Scraping Python Tools
1.4 learning about the Python Compiler
1.5 Python History
1.6 Python Installation
1.6.1 Step 1: Select Version of Python to Install
1.6.2 Step 2: Download Python Executable Installer
1.6.3 Step 3: Run Executable Installer
1.6.4 Step 4: Verify Python Was Installed on Windows
1.6.5 Step 5: Verify Pip Was Installed
1.6.6 Step 6: Add Python Path to Environment Variables (Optional)
1.6.7 Step 7: Install virtualnv (Optional)
1.7 How to Write a Python Program
1.8 Conclusion
Chapter 2: Data Types and Variables
2.1 Python Integer Values
2.1.1 Complex Numbers
2.2 Variables and Assignment
2.3 Identifiers in Python
2.4 Various Types of Floating Point Numbers
2.5 Control Codes within Strings
2.6 User Input
2.7 Evaluation (eval()) Function
2.8 Controlling (print()) Function
2.9 Conclusion
Chapter 3: Operators
3.1 Python Expressions and Operators
3.1.1 Comparison Operators
3.1.1.1 Floating-Point Value Equality Comparison
3.1.2 Logical Operators
3.1.2.1 Logical Expressions Using Boolean Operands
3.1.2.2 Evaluation of Boolean and Non-Boolean Expressions
3.1.3 Chained Comparisons
3.1.4 Bitwise Operators
3.1.5 Identity Operators
3.1.6 Augmented Assignment Operators
3.1.7 Comparison of Arithmetic and Bitwise Operators
3.2 Operator Associativity and Precedence
3.3 Comments in Python Programming
3.4 Bugs in Programs
3.4.1 Syntax Errors
3.4.2 Run-time Errors
3.4.3 Logic Errors
3.5 Examples of Arithmetic
3.6 Algorithms
3.7 Conclusion
Chapter 4: Branch Control Structure
4.1 Boolean Expressions
4.2 Additional Boolean Statements
4.3 The Simple If Statement
4.4 If/Else Control Statements
4.5 Compound Boolean Expressions
4.6 Nested If/Else Conditional Statements
4.7 Multipile Decision-Making Statements
4.8 Expressions of Decision-Making Conditional Statements
4.9 Errors in Decision-Making Statements
4.10 Conclusion
Chapter 5: Iterative Control Structure
5.1 The While Loop
5.2 Difference Between Definite and Indefinite Loops
5.3 The For Loop
5.4 Nested Loop Statements
5.5 Abnormal Loop Termination
5.5.1 The ‘Break’ Statement
5.5.2 ‘Continue’ Statements
5.6 Infinite Looping Statement
5.7 Examples of Iteration
5.7.1 Computation of a Square Root
5.7.2 Structure of Tree Drawing
5.8 Program to Print Prime Numbers
5.8.1 Inputs
5.9 Conclusion
Chapter 6: Functions
6.1 Introduction to Functions
6.1.1 Built-in Functions
6.1.2 User-defined Functions
6.2 The Meaning of a Function
6.3 Documenting Functions
6.3.1 Importance of Documenting a Function
6.3.2 Documenting Functions with Python Docstrings
6.3.3 Python Docstring Formats
6.4 GCD Function
6.5 The Main Function
6.6 The Calling Function
6.7 Argument Passing in Parameters (Actual and Formal)
6.7.1 Parameters vs. Arguments
6.7.2 Function Arguments in Python
6.7.3 Global vs. Local Variables
6.7.4 Anonymous Functions in Python
6.8 The Return Statement and Void Function
6.9 Scope of Variables and Their Lifetimes
6.10 Function Examples
6.10.1 Function to Generate Prime Numbers
6.10.2 Command Interpreter
6.10.3 Restricted Input
6.10.4 Die Rolling Simulation
6.10.5 Tree Drawing Function
6.11 Arguments Passed by Reference Value
6.12 Recursion
6.13 Default Arguments
6.14 Time Functions
6.15 Random Functions
6.16 Reusable Functions
6.17 Mathematical Functions
6.18 Conclusion
Chapter 7: Lists
7.1 Introduction to Lists
7.2 Creating Lists
7.3 Fundamental List Operations
7.3.1 List () Functions
7.4 Slicing and Indexing in Lists
7.4.1 Modifying List Items
7.5 Built-In Functions Used in Lists
7.6 List Methods
7.6.1 Populating Lists Items
7.6.2 List Traversing
7.6.3 Nested Lists
7.7 Del Statement
7.8 List Operations
7.8.1 Searching Problem
7.8.1.1 Linear Search
7.8.1.2 Binary Search
7.8.2 Sorting
7.8.2.1 Selection Sort
7.8.2.2 Merge Sort
7.8.2.3 Sorting Comparison
7.9 Reversing of Lists
7.10 Conclusion
Chapter 8: Dictionaries
8.1 Introduction
8.2 How a Dictionary Is Created
8.3 Accessing and Altering Key: Value Pairs in Dictionaries
8.3.1 The dict () Function
8.4 Dictionaries with Built-in Functions
8.5 Dictionary Methods
8.5.1 Population of Primary Dictionaries: Value Pairs
8.5.2 Dictionary Traversing
8.6 The Del Statement
8.7 Conclusion
Chapter 9: Tuples and Sets
9.1 Creating Tuples
9.2 Basic Tuple Operations
9.2.1 The tuple () Function
9.3 Indexing and Slicing in Tuples
9.4 Built-in Functions of Tuples
9.5 Comparison Between Tuples and Lists
9.6 Comparsion Between Tuples and Dictionaries
9.7 Tuple Methods
9.7.1 Tuple Packing and Unpacking
9.7.2 Tuples Traversing
9.7.3 Tuples with Items
9.8 Use of the Zip() Function
9.9 Python Sets
9.10 Set Methods
9.10.1 Traversing of Sets
9.11 The Frozen Set
9.12 Conclusion
Chapter 10: Strings and Special Methods
10.1 Introduction
10.2 Creating and Storing Strings
10.2.1 String str() Function
10.3 Basic String Operation
10.3.1 String Comparison
10.3.2 Built-in Functions Used on Strings
10.4 Accessing Characters by the Index Number in a String
10.5 Slicing and Joining in Strings
10.5.1 Specifying the Steps of a Slice Operation
10.5.2 Joining Strings Using the join() Method
10.5.3 Split Strings Using the split () Method
10.5.4 Immutable Strings
10.5.5 String Traversing
10.6 String Methods
10.7 Formatting Strings
10.7.1 Format Specifiers
10.7.2 Escape Sequences
10.7.3 Raw Strings
10.7.4 Unicodes
10.8 Conclusion
Chapter 11: Object-oriented Programming
11.1 Introduction
11.2 Classes and Objects
11.3 Creating Classes in Python
11.4 How to Create Objects in Python
11.5 The Constructor Method
11.6 Classes with Multiple Objects
11.6.1 Using Objects as Arguments
11.6.2 Objects as Return Values
11.7 Difference Between Class Attributes and Data Attributes
11.8 Encapsulation
11.8.1 Using Private Instance Variables and Methods
11.9 Inheritance
11.10 Polymorphism
11.10.1 Python Operator Overloading
11.11 Conclusion
Chapter 12: GUI Programming Using Tkinter
12.1 Introduction
12.2 Getting Started with Tkinter
12.3 Processing Events
12.4 The Widget Classes
12.4.1 Toplevel
12.4.2 Frames
12.4.3 Labels
12.4.4 Buttons
12.4.5 Entry
12.4.6 Radio Buttons
12.4.7 Check Buttons
12.4.8 Messages
12.4.9 List Boxes
12.5 Canvases
12.6 Geometry Managers
12.7 Loan Calculators
12.8 Displaying Images
12.9 Menus
12.10 Popup Menus
12.11 The Mouse, Key Events and Bindings
12.12 Animations
12.13 Scrollbars
12.14 Standard Dialog Boxes
12.15 Conclusion
Chapter 13: Python Exception Handling: GUI Programming Using Tkinter
13.1 Introduction
13.2 Exception Examples
13.3 Common Gateway Interfaces
13.4 Database Access in Python
13.4.1 What is MySQLdb?
13.4.2 Database Connection
13.5 The Read Operation
13.6 Python Multithreaded Programming
13.6.1 Starting a New Thread
13.6.2 The Threading Module
13.6.3 Thread Module
13.6.4 Priority Multithreaded Queue
13.7 Networking in Python
13.7.1 What Are Sockets?
13.7.2 The Socket Module
13.8 Conclusion
Chapter 14: Case Studies
Python Case Study 1
N Queens on an N×N Chessboard
Python code
Explanation of the Code
Python Case Study 2
Finding the Best Move
Minimax
Checking for GameOver State
Making our AI Smarter
Case Study 3: Eight-puzzle Problem
Ideal Cost Function for Eight-puzzle Algorithm
Program Code
Case Study 4: Bouncing Ball
Code
Case Study 5: Animations
How the Animation Program Works
Case Study 6: Shortest Path
Code
Case Study 7: Tree Traversal Algorithm
Binary Tree and Its Traversal Using Python
Code
References
Index