This book is an introduction to Python Programming and provides a practical approach to the subject. The basic concepts of Python are explained in detail and augmented with examples and diagrams for a thorough understanding of the subject.
The book is primarily aimed at students with little or no prior knowledge of programming languages. However, self-taught and hobbyist programmers, scientists, engineers, computing professionals and computer scientists and others who need to program as part of their work may also use this book for understanding the basic concepts of Python.
Author(s): M. Shubhakanta Singh
Publisher: CRC Press
Year: 2023
Language: English
Pages: 362
City: New Delhi
Cover
Half Title
Title Page
Copyright Page
Dedication
Brief Contents
Table of Contents
Preface
Acknowledgement
1. Introduction
1.1 What is a Computer?
1.2 Basics of Programming Languages
1.2.1 Machine Language
1.2.2 Assembly Language
1.2.3 High Level Languages
1.3 Interpreter and Compiler
1.4 Algorithms and Flowcharts
1.4.1 Writing Algorithms
1.4.2 Flowcharts
1.5 Writing Algorithms and Flowcharts for A Few Important Problems
1.5.1 Reversing the Digits of a Given Integer
1.5.2 To Verify Whether an Integer is a Prime Number or Not
1.5.3 To Organize a given Set of Numbers in Ascending Order
1.5.4 To Find the Square Root of an Integer
1.5.5 To Find the Factorial for a Given Number
1.5.6 To Generate the Fibonacci Series for n Terms
1.5.7 To Find the Value of the Power of a Number Raised by Another Integer
1.5.8 To Reverse the Order Elements of an Array
1.5.9 To Find the Largest Number in an Array
1.5.10 To Solve a Quadratic Equation
1.6 Why Python?
1.7 Installing Python
1.7.1 Windows
1.7.2 Linux and UNIX
1.7.3 Macintosh
1.8 Other Python Distributions
1.9 Keeping in Touch and Up-to-Date
Exercises
2. Identifiers and Data Types
2.1 Keywords
2.2 Identifiers
2.2.1 Rules for Identifiers
2.3 Data Types
2.4 Values and Types
2.5 Backslash Character Constants
2.6 Variables
Exercises
3. Operators and Expressions
3.1 Arithmetic Operators
3.1.1 Integer Arithmetic
3.1.2 Large Integers
3.1.3 Hexadecimals and Octals
3.1.4 Real Arithmetic
3.1.5 Mixed Mode Operations
3.1.6 Rules for Conversion
3.1.7 Explicit Conversions
3.2 Relational Operators
3.2.1 More Relational Operators
3.2.2 Is : The Identity Operator
3.3 Logical/Boolean Operators
3.4 Assignment Operators
3.5 Interactive Mode and Script Mode
3.6 Order of Operations
3.7 Comments in Python
3.8 __Future__ in Python
3.9 How to Track Errors?
3.10 Common Errors
3.10.1 Syntax Errors
3.10.2 Runtime Errors
3.10.3 Semantic Errors
Exercises
4. Managing Input and Output Operations
4.1 Managing Inputs
4.1.1 raw_input() and input() functions
4.2 Managing Outputs
4.2.1 repr() or str() Functions
4.2.2 rjust() and format() Functions
4.3 Frequently used Formatting Specifiers
Exercises
5. Decision Making and Branching
5.1 If Statement
5.1.1 Simple if Statement
5.1.2 if else Statement
5.1.3 Nested if else Statement
5.1.4 else if (elif) Ladder Statement
5.2 Boolean Values (True or False)
Exercises
6. Decision Making and Looping
6.1 The While Loop Statement
6.2 The for Loop Statement
6.3 The range() Function
6.3.1 range (argument1) function
6.3.2 range (argument1, argument2) function
6.3.3 range (argument1, argument2, argument3) function
6.4 The xrange() Function
6.5 Jumps in Loops
6.6 Skipping a part of a Loop
6.7 The else Clauses on Loops
Exercises
7. Functions
7.1 Types of Functions
7.1.1 Built in Functions
7.1.2 User Defined Functions
7.2 Incremental Development
7.3 Nesting of Functions
7.4 Boolean Function
7.5 Recursion Function
7.6 Checking Types : isinstance ( )
7.7 Designing and Writing Modules
7.8 Global and Local Variables
7.9 Default Arguments
Exercises
8. List
8.1 Definition
8.2 The in Operator
8.3 Traversing in a List
8.4 Nested List
8.5 List Operations
8.6 List Slices
8.7 List Functions
8.8 List Methods
8.9 Splitting a String into a List
8.10 Inputting List from the Console/Keyboard
8.11 Shifting Lists
8.12 Simplifying Coding with List
8.13 Copying List
8.14 Passing Lists to Functions
8.15 Searching Lists
8.15.1 The Linear Search Method
8.15.2 The Binary Search Method
8.16 Sorting Lists
8.16.1 Selection Sort
8.16.2 Insertion Sort
8.17 Two-Dimensional Lists
8.17.1 Processing Two-Dimensional Lists
8.17.2 Initializing Lists with Input Values
8.17.3 Initializing Lists with Random Values
8.17.4 Printing Two-Dimensional List
8.17.5 Summing All Elements
8.17.6 Summing Elements by Column
8.17.7 Finding the Row with the Largest Sum
8.17.8 Random Shuffling
8.17.9 Passing Two-Dimensional Lists to Functions
8.18 Application: Finding the Closest Pair
8.19 Multidimensional Lists
Exercises
9. Dictionaries
9.1 Definition
9.2 Creating a Dictionary
9.3 Adding, Modifying, and Retrieving Values
9.4 The Dictionary Methods
9.5 Deleting Items
9.6 Looping Items
9.7 Equality Test
9.8 Dictionaries of Dictionaries
9.9 Sets
9.10 Accessing Sets With Common Functions
9.11 Subset and Superset in Sets
9.12 Relational operators in Sets
9.13 Set Operations
Exercises
10. Tuples
10.1 Definition
10.2 Tuple Assignment
10.3 Tuples as Return Values
10.4 The Basic Tuple operations
10.5 Variable-length Argument Tuples
10.6 Relationship between Lists and Tuples
10.7 Relationships between Dictionaries and Tuples
Exercises
11. Files
11.1 Introduction
11.2 Text Files and Binary Files
11.3 Absolute and Relative Filename
11.4 Opening a File
11.5 Writing Data
11.6 Some Commonly used Methods for File Handling
11.7 Writing and Reading Numeric Data
Exercises
12. Computational Physics–Application in Physical Systems
12.1 Introduction
12.2 What is Computational Physics?
12.3 Oscillatory Motion
12.3.1 Ideal Simple Harmonic Oscillator
12.3.2 Motion of a Damped Oscillator
12.4 Stationary States and Time Independent SchrÖdinger Equation
12.4.1 Introduction
12.4.2 Form of Potential
12.4.3 Eigen Value Problem
12.5 Fractals
12.5.1 Fractional Dimension (Math)
12.5.2 The Sierpinski Gasket
12.5.3 Assessing Fractal Dimension
12.5.4 Beautiful Plants
12.6 Random Numbers in Computer Simulation
12.6.1 Introduction
12.6.2 Randomness: Some Intuitive Concepts
12.6.3 Random Number Generators
12.6.4 Pseudo-Random Number Generators
12.6.5 Basic Strategy
12.6.6 Mid-Square Generator
12.6.7 Multiplicative Congruential Generator
12.6.8 Mixed Multiplicative Congruential Generator
12.6.9 Tests for Randomness
12.7 Monte Carlo Method
12.7.1 Introduction
12.7.2 Multi-Dimensional Integrals:
12.7.3 Monte Carlo Method: Hitting The Bull’s Eye Blind-Folded
12.7.4 Application of the Monte Carlo Method: Finding the Value of π
12.8 Lorenz Equation
Exercises
Appendix I: Objective Type Questions
Appendix II: Descriptive Type Questions
References
Index