Python for Engineers and Scientists: Concepts and Applications

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

The text focuses on the basics of Python programming fundamentals and introduction to present-day applications in technology and the upcoming state-of-art trends in a comprehensive manner. The text is based on Python 3.x and it covers the fundamentals of Python with object-oriented concepts having numerous worked-out examples. It provides a learning tool for the students of beginner level as well as for researchers of advanced level. Each chapter contains additional examples that explain the usage of methods/functions discussed in the chapter. It provides numerous programming examples along with their outputs.

The book:

  • Includes programming tips to highlight the important concepts and help readers avoid common programming errors
  • Provides programming examples along with their outputs to ensure the correctness and help readers in mastering the art of writing efficient Python programs
  • Contains MCQs with their answers; conceptual questions and programming questions; and solutions to some selected programming questions, for every chapter
  • Discusses applications like time zone converter and password generators at the end
  • Covers fundamental of Python up to object oriented concepts including regular expression

The book offers a simple and lucid treatment of concepts supported with illustrations for easy understanding, provides numerous programming examples along with their outputs, and includes programming tips to highlight the important concepts. It will be a valuable resource for senior undergraduate, graduate students, and professionals in the fields of electrical engineering, electronics and communication engineering, and computer engineering.

Author(s): Rakesh Nayak, Nishu Gupta
Publisher: CRC Press
Year: 2022

Language: English
Pages: 457
City: Boca Raton

Cover
Half Title
Title Page
Copyright Page
Dedication
Table of Contents
Foreword
Foreword
Preface
Acknowledgments
Authors
Section I Python Fundamentals
Chapter 1 Interaction with Python
Learning Objectives
1.1 Introduction
1.2 Variables and Identifiers
1.2.1 How to Name Identifiers
1.2.2 Use of Descriptive Identifiers and Comments
1.2.3 Variable Types
1.2.3.1 Numeric Datatypes
1.2.3.2 None Datatype
1.2.3.3 Sequence Datatypes
1.2.3.4 Set Datatype
1.2.3.5 Mapping Datatype
1.2.3.6 Array Datatype
1.3 Constant
1.4 Statement and Expression
1.5 Input Statements
1.6 Output Statements
1.7 Formatting Output Statements
1.7.1 Escape Character
1.7.2 sep and end
1.7.3 String Formatting with format()
1.7.4 Numbers Formatting with format()
1.8 Comment Statement
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 2 Operators
Learning Objectives
2.1 Introduction
2.2 Types of Operators
2.2.1 Assignment Operator
2.2.2 Arithmetic Operators
2.2.2.1 Precedence of Arithmetic Operators
2.2.3 Relational Operators
2.2.4 Logical Operators
2.2.4.1 and Operator
2.2.4.2 or Operator
2.2.4.3 not Operator
2.2.5 Increment and Decrement Operators
2.2.6 Bitwise Operators
2.2.6.1 Bitwise AND Operator (&)
2.2.6.2 Bitwise OR Operator (|)
2.2.6.3 Bitwise XOR Operator (^)
2.2.6.4 Bitwise Complement (~)
2.2.6.5 Bitwise Left Shift (<<)
2.2.6.6 Bitwise Right Shift (>>)
2.2.7 Membership Operators
2.2.8 Identity Operators
2.2.9 Precedence of all Operators
2.3 Type Casting
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 3 Control Structures
Learning Objectives
3.1 Introduction
3.2 Conditional Statements
3.2.1 Conditional if-else
3.2.2 Conditional if-elif-else
3.2.3 Nested if-elif-else Statements
3.2.4 Ternary Operator
3.3 Loops
3.3.1 while-loop
3.3.2 for-loop
3.3.2.1 The range() Function
3.3.3 Continue, Break and Pass
3.3.3.1 Continue Statement
3.3.3.2 Break Statement
3.3.3.3 Pass Statement
3.3.4 Nested Loops
3.4 Looping through Two Lists
3.5 Iterator
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 4 String
Learning Objectives
4.1 Introduction
4.2 Strings
4.2.1 Creating String
4.2.1.1 Creating an Empty String
4.2.1.2 Creating a String from Numbers
4.2.1.3 Creating a String from List and Tuple
4.2.2 Accessing String
4.2.2.1 Membership in String
4.2.3 String Operations
4.2.3.1 Concatenation
4.2.3.2 Repetition
4.2.4 Character Encoding
4.2.5 String Functions and Methods
4.2.5.1 len()
4.2.5.2 del()
4.2.5.3 max()
4.2.5.4 min()
4.2.5.5 capitalize()
4.2.5.6 lower()
4.2.5.7 upper()
4.2.5.8 title()
4.2.5.9 replace()
4.2.5.10 split()
4.2.5.11 strip()
4.2.5.12 count()
4.2.5.13 isalpha()
4.2.5.14 isupper()
4.2.6 String Slicing
4.2.6.1 String Slicing with Negative Index
4.2.6.2 String Slicing with Step
4.2.6.3 String Slicing Default Index
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 5 List and Tuple
Learning Objectives
5.1 Introduction
5.2 List
5.2.1 Creating List
5.2.1.1 Creating an Empty List
5.2.1.2 Creating a List from a String
5.2.1.3 Creating a List by Range Function
5.2.1.4 Creating a List from Another List
5.2.2 List Operations
5.2.2.1 Concatenation (+)
5.2.2.2 Repetition (*)
5.2.3 Accessing List
5.2.3.1 Membership in List
5.2.4 List Functions and Methods
5.2.4.1.1 len()
5.2.4.1.2 del()
5.2.4.1.3 max()
5.2.4.1.4 min()
5.2.4.1.5 append()
5.2.4.1.6 insert()
5.2.4.1.7 pop()
5.2.4.1.8 remove()
5.2.4.1.9 extend()
5.2.4.1.10 index()
5.2.4.1.11 count()
5.2.4.1.12 sort()
5.2.4.1.13 sorted()
5.2.4.1.14 reverse()
5.2.4.1.15 copy()
5.2.4.1.16 clear()
5.2.4.1.17 reversed()
5.2.4.1.18 enumerate()
5.2.4.1.19 any()
5.2.4.1.20 all()
5.2.5 List Slicing
5.2.5.1 List Slicing with Negative Index
5.2.5.2 List Slicing with Step
5.2.5.3 List Slicing Default Index
5.2.6 Difference between Assignment and Copying a List
5.3 Multi-Dimensional Lists
5.3.1 Retrieval from Multi-Dimensional Lists
5.4 Tuples
5.4.1 Creating a Tuple
5.4.1.1 Creating a Tuple with no Item
5.4.1.2 Creating a Tuple with a Single Item
5.4.1.3 Nesting Tuples
5.4.1.4 Creating a Tuple from List
5.4.1.5 Creating a Tuple from a String
5.4.2 Tuple Operations
5.4.2.1 Concatenation (+) Operation
5.4.2.2 Repetition (*) Operation
5.4.3 Tuple Assignment
5.4.4 Accessing Objects in Tuple
5.4.4.1 Membership in Tuple
5.5.5 Updating Tuples
5.4.6 Tuple Functions and Methods
5.4.7 Tuple Slicing
5.5 Advantages of Tuple over List
Multiple Choice Questions – List
Multiple Choice Questions – Tuple
Descriptive Questions – List
Descriptive Questions – Tuple
Programming Questions – List
Programming Questions – Tuple
Answer to Multiple Choice Questions – List
Answer to Multiple Choice Questions – Tuple
Chapter 6 Dictionary
Learning Objectives
6.1 Introduction
6.2 Dictionaries
6.2.1 Creating a Dictionary
6.2.1.1 Creating a Dictionary with no item
6.2.1.2 Creating a Dictionary with { }
6.2.1.3 Creating a Dictionary with dict( )
6.2.1.4 Creating a Default Dictionary
6.2.1.5 Creating a Dictionary from a List
6.2.1.6 Insertion of a New Key–Value
6.2.2 Dictionary Assignment
6.2.3 Accessing Dictionary
6.2.3.1 keys()
6.2.3.2 items()
6.2.3.3 get()
6.2.3.4 Membership in Dictionary
6.2.4 Dictionary Methods
6.2.4.1 update()
6.2.4.2 sorted()
6.2.4.3 str()
6.2.4.4 setdefault()
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 7 Set
Learning Objectives
7.1 Introduction
7.2 Set
7.2.1 Creating a Set
7.2.1.1 Creating an Empty Set
7.2.1.2 Creating a Set from a List, Tuples and String
7.2.1.3 Creating a Set from a Dictionary
7.2.2 Accessing Set Elements
7.2.2.1 Membership in Set
7.2.3 Set Operations
7.2.3.1 union()
7.2.3.2 intersection()
7.2.3.3 difference()
7.2.3.4 Exclusive-OR
7.2.3.5 Symmetric Difference
7.2.3.6 Equivalent Set and Not Equivalent
7.2.3.7 Subset and Superset
7.2.3.8 Proper Subset and Proper Superset
7.2.4 Set Function and Methods
7.2.4.1 add()
7.2.4.2 discard()
7.2.4.3 isdisjoint()
7.2.4.4 issubset()
7.2.4.5 issuperset()
7.2.4.6 Frozen Set
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 8 Functions
Learning Objectives
8.1 Introduction
8.2 Functions
8.3 Parameterized Function
8.3.1 Positional and Keyword Parameters
8.3.2 Default Parameter
8.3.3 Function with a Variable Number of Arguments
8.4 The Return Statement
8.5 Namespace and Scope of a Variable
8.6 Recursive Function
8.7 Lambda Function
8.7.1 filter()
8.7.2 map()
8.7.3 reduce()
8.7.4 zip()
8.8 Generators
8.9 Python Modules
8.9.1 Importing a Module
8.9.2 Aliasing
8.9.3 User-Defined Module
8.10 Closures
8.11 Decorators
8.11.1 Passing a Parameter to a Decorator
8.11.2 Decorator Chaining
8.12 Some Special Methods and Attributes
8.12.1 __name__
8.12.2 __module__
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 9 File Handling
Learning Objectives
9.1 Introduction
9.2 File IO
9.2.1 File Opening and Closing
9.2.2 File Properties
9.2.3 File Reading
9.2.4 File Writing
9.2.5 Binary File Reading/Writing
9.2.6 CSV File Reading/Writing
9.3 File Position
9.4 Some More File Operations
9.5 Operating System–Related Operations
9.6 The “with” Statement
9.7 Pickling
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Section II Object Oriented Concepts in Python
Chapter 10 Classes and Objects
Learning Objectives
10.1 Introduction to Object-Oriented Programming
10.2 Class and Object
10.2.1 Defining a Class
10.2.2 Generating an Object
10.2.3 The __init__() , __new__() and __del__() Methods
10.2.3.1 __init__()
10.2.3.2 __new__()
10.2.3.3 __del__()
10.3 Variables and Methods
10.3.1 Variables (Attributes)
10.3.1.1 Object Variables (Instance Variables)
10.3.1.2 Class Variables (Static Variables)
10.3.2 Accessing Variables
10.3.2.1 Accessing the Variable by Object Reference
10.3.2.2 Accessing the Variable by Class Name
10.3.2.3 Accessing the Static Variable Outside the Class by Class Name
10.4 Public, Private and Protected Variables
10.4.1 Variable Starts Without Any _ (Underscore) Symbol
10.4.2 Variable Starts with _ (Single Underscore) Symbol
10.4.3 Variable Starts with __ (Two Underscores) symbols
10.5 Methods
10.5.1 Instance Method
10.5.2 Class Method
10.5.3 Static Method
10.6 Class Inside a Class (Inner Class)
10.6.1 Object of the Inner Class Is Created Inside the Outer Class
10.6.2 Object of the Inner Class Is Created Outside the Outer Class
10.6.3 Accessing Attributes of Inner Class
10.6.3.1 Accessing the Attributes of Inner Class Outside the Class
10.6.3.2 Accessing the Attributes of Inner Class in the Outer Class
10.6.3.3 Accessing the Attributes of Inner Class Outside the Outer Class
10.6.3.4 Accessing the Attributes of Inner Class When Inner Class and Outer Class Have the Same Method
10.7 Some Special Methods and Attributes
10.7.1 __dict__ ()
10.7.2 __name__()
10.7.3 __doc__
10.7.4 hasattr()
10.7.5 getattr()
10.7.6 setattr(obj,name,value)
10.7.7 delattr()
10.7.8 del
10.7.9 isinstance()
10.7.10 repr()
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 11 Inheritance
Learning Objectives
11.1 Introduction
11.1.1 Single-Level inheritance
11.1.2 Multi-Level Inheritance
11.1.3 Multiple Inheritance
11.1.4 Hierarchical Inheritance
11.1.5 Hybrid inheritance
11.2 Initialization in Inheritance
11.2.1 __init__() for the Child Class Only Is Defined
11.2.2 __init__() for the Base Class Only Is Defined
11.2.3 __init__() for Both Sub Class and Super Class Is Defined
11.3 Method Resolution Order
11.4 Specialized Methods
11.4.1 issubclass()
11.4.2 __bases__
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 12 Polymorphism
Learning Objectives
12.1 Introduction
12.1.1 Duck-Typing
12.1.2 Operator Overloading
12.1.3 Method Overloading
12.1.4 Method Overriding
12.2 Encapsulation
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 13 Abstract Class, Aggregation, Composition
Learning Objectives
13.1 Introduction – Abstract Class
13.2 Abstract Class and Abstract Method
13.3 Relationship
13.3.1 Association Relationship
13.3.2 Aggregation (Uses a) Relationship
13.3.3 Composition (Has a) Relationship
13.4 Difference between Inheritance and Association
13.5 Difference between Aggregation and Composition
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Chapter 14 Exception Handling
Learning Objectives
14.1 Errors and Exceptions
14.2 The try:, except:, else: and finally: Block
14.2.1 The try: and except: Block
14.2.2 The try:, except: and else: Block
14.2.3 The try:, except :, else: and finally: Block
14.2.4 Mentioning the Error Description
14.3 The Exception Hierarchy
14.4 Exception in a Function
14.5 The Raised Exception
14.6 User Defined Exceptions
14.7 Assertion
Worked Out Examples
Multiple Choice Questions
Descriptive Questions
Programming Questions
Answer to Multiple Choice Questions
Index