Basics of Python Programming: A Quick Guide for Beginners - Krishna Kumar Mohbey - E-Book

Basics of Python Programming: A Quick Guide for Beginners E-Book

Krishna Kumar Mohbey

0,0
53,95 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Basics of Python Programming: A Quick Guide for Beginners is an essential companion to mastering the Python programming language. The book presents information about Python in 12 structured chapters with a strong emphasis on fundamentals and practical information. Starting with basic operators, functions and expressions, contents explain file handling, exception handling and modules. The book concludes with advanced topics such as object oriented programming and machine learning.

Key Features:

Fundamental Focus: Covers the core concepts of Python programming to build a strong foundation in python programming in an easy-to-understand format.
Practical Demonstrations: Learn by doing. This textbook includes hands-on practical demonstrations that reinforce your understanding of Python concepts.
IDE Guidance: Includes programming and installation guidance for Python-supporting Integrated Development Environments (IDEs).
Explores Python Frameworks: Introduces Python frameworks such as Matplotlib, TensorFlow, PyTorch, Scikit-Learn, and NLTK for complex projects.
Python for Machine Learning: Gives a preliminary understanding of Python for machine learning tasks for data science and AI applications.

Basics of Python Programming: A Quick Guide for Beginners is the perfect starting point for aspiring students, programmers and tech enthusiasts. Whether you're a student looking to build a solid foundation in Python or an industry professional venturing into machine learning and artificial intelligence, this textbook has you covered.

Readership
Computer science, engineering and technology students; programming enthusiasts and professionals.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 163

Veröffentlichungsjahr: 2001

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents
BENTHAM SCIENCE PUBLISHERS LTD.
End User License Agreement (for non-institutional, personal use)
Usage Rules:
Disclaimer:
Limitation of Liability:
General:
FOREWORD
PREFACE
Introduction to Python
Abstract
INTRODUCTION
Technical Strengths of Python
Portability
Object-Oriented
Community Support
Advanced Features
Memory Management
Ease of Use
Installing Python
Windows Installer
Ubuntu
Linux Mint
Python IDLE
Anaconda Open-source Distribution
Installing Anaconda on Windows
Installing Anaconda on Linux
First Python Program
Python Keywords
Identifiers
Statements
Indentation
Comments
Coding Styles
Functional
Imperative
Procedural
Object-oriented
CONCLUDING REMARKS
Data Types, Operators, and Expressions
Abstract
INTRODUCTION
NUMBER
Sequence
DICTIONARY
BOOLEAN
SET
TYPE CONVERSION
Implicit Type Conversion
Explicit Type Conversion
OPERATORS
Arithmetic Operators
Addition (+) Operator
Subtraction (-) Operator
Multiplication (*) Operator
Division (/) Operator
Modulus (%) Operator
Exponent (**) Operator
Floor Division (//) Operator
Relational Operators
Greater than (>) Operator
Greater than or equal to (>=) Operator
Less than (<) Operator
Less than or equal to (<=) Operator
Equal to (==) Operator
Not equal to (! =) Operator
Assignment Operator
Assignment (=) Operator
Add AND (+=) Operator
Subtract AND (-=) Operator
Multiply AND (*=) Operator
Divide AND (/=) Operator
Modulus AND (%=) Operator
Exponent AND (**=) Operator
Floor Division (//=) Operator
Unary Operators
Bitwise Operators
Binary AND (&) Operator
Binary OR (|) Operator
Binary XOR (^) Operator
Binary One's Complement (~) Operator
Binary Left Shift (<<) Operator
Binary Right Shift (>>) Operator
Logical Operators
Logical AND Operator
Logical OR Operator
Logical NOT Operator
Membership Operators
Operator (in)
Operator (not)
Identity Operators
Operator (is)
Operator (is not)
Operators' Precedence and Associativity
EXPRESSIONS
Identifiers
Literals
Operators
STRING OPERATIONS
Accessing Values in Strings
Triple Quotes
CONCLUDING REMARKS
Control Flow
Abstract
INTRODUCTION
SEQUENTIAL STATEMENTS
DECISION CONTROL STRUCTURES
If Statements
If-else Statements
Nested if
if-elif-else
LOOPING STATEMENTS
For Loop
While Loop
Nested Loop
Break Statement
Continue Statement
The Pass Statement
CONCLUDING REMARKS
Functions
Abstract
INTRODUCTION
Definition
PREDEFINED FUNCTIONS
USER-DEFINED FUNCTIONS
Function Call
Function Parameters and Arguments
Default Arguments
Variable Scope and Lifetime
Scope of the Variable
Local Scope
Global Scope
The Lifetime of the Variable
Local and Global Variables
Global Variables
Global Statement
Return Statement
Lambda Functions
Recursive Functions
Function Redefinition
CONCLUDING REMARKS
Sequence-String and List
Abstract
INTRODUCTION
STRING
String Concatenation
Using + Operator
Using join() Method
Using % Operator
Using Format() Function
Appending Strings
Using += Operator
Using Join()
Multiplying Strings
Immutable Strings
String Formatting Operator
Built-in String Functions
Slice Operation
The ord() Function
The chr() Function
String Comparison
Using Relational Operators
Using is and is not
Using User-defined Function
Iterating String
split() Function
re.findall() Function
The String Module
String Module Constants
string.ascii_letters
string.ascii_lowercase
string.ascii_uppercase
string.digits
string.hexdigits
string.punctuation
String capwords() Function
String Module Classes
Formatter
Template
Regular Expression
LISTS
Using List Index
List Operations
Updating Values in Lists
Nested List
Aliasing
Cloning Lists
Cloning List using Slicing
Cloning List using Extend()
Cloning List using List()
Cloning List using List Comprehension
Cloning List using Append()
Cloning List using Copy()
Built-in Functions
List Built-in List Methods
List as Arrays
Loops in Lists
For Loop in the List
While Looping in the List
List Comprehension
Enumerate() Method
Numpy in Loop
List in Functions
CONCLUDING REMARKS
Tuple and Dictionaries
Abstract
INTRODUCTION
TUPLE
TheTuple ()Function
Accessing Tuple
Tuple Indexes
Tuple Slicing
Updating Tuple
Deleting Elements from a Tuple
Tuple Operations
Tuple Basic Functions
Tuple Assignment
Tuples and Functions
Nesting of Tuples
Tuples from String and List
zip() Function
Inverse zip(*) Function
Tuple Sorting
DICTIONARY
Dictionary Creation
Accessing Dictionary Values
Modifying Dictionary
Delete an Element from the Dictionary
The Clear () Function
Sorting Dictionaries
Sorting Dictionary by Value
Sorting Dictionary in Reverse Order
Iterating Over a Dictionary
Nested Dictionaries
Updating Nested Dictionary
Deleting Elements from a Nested Dictionary
Deleting a Dictionary from the Nested Dictionary
Iterating Through a Nested Dictionary
Built-in Dictionary Functions
The Copy () Method
Formatting Dictionaries
CONCLUDING REMARKS
File Handling
Abstract
INTRODUCTION
FILE
Open() Function
Close() Function
Write() Function
Writelines() Method
Writing Numbers to a File
Read() Method
Readline() Method
Readlines() Method()
Reading Contents with a Loop
Creating a New File
File Object Attributes
File Positions
File Rename
Deleting a File
Binary Files
Directory Operations
Current Working Directory
List of Directories
Creating a Directory
Change Directory
Renaming a Directory
Delete a Directory
CONCLUDING REMARKS
Exception Handling
Abstract
INTRODUCTION
HANDLING EXCEPTIONS
EXCEPT BLOCK
ELSE AND FINALLY, KEYWORD
RAISING EXCEPTIONS
Built-in Exceptions
User-defined Exceptions
CONCLUDING REMARK
Modules and Packages
Abstract
Introduction
Modules
Import Statement
From…Import Statement
Renaming A Module
Dir() Built-In Function
Reload () Function
Built-In Modules
PACKAGE
Creating Package
Sub Packages
CONCLUDING REMARK
Object-Oriented Programming
Abstract
INTRODUCTION
CLASS AND OBJECT
DATA ABSTRACTION
ENCAPSULATION
INHERITANCE
POLYMORPHISM
Defining a Class
Creating an Object
Deleting Properties or Object
Data Abstraction Example
CONSTRUCTORS
Parameterized Constructor
Default Constructor
INHERITANCE IN PYTHON
TYPES OF INHERITANCE
Single Inheritance
Multi-level Inheritance
Multiple Inheritance
Hierarchical Inheritance
The issubclass(sub,sup) method()
The isinstance (obj, class) method()
POLYMORPHISM IN PYTHON
Polymorphism in Operators
Function Polymorphism
Polymorphism in Class Methods
Method Overriding
Built-in Class Functions
Built-in Class Attributes
Static Variables
CONCLUDING REMARKS
Python for Machine Learning
Abstract
INTRODUCTION
IMPORTANT PYTHON LIBRARIES
• NUMPY
• PANDAS
• SCIKIT-LEARN
• MATPLOTLIB
• TENSORFLOW
• KERAS
• PYTORCH
• NLTK
Installing NLTK on Mac/ Unix
Installing NLTK on Windows
CONCLUDING REMARKS
Programming with Python
Abstract
INTRODUCTION
BASIC PYTHON PROGRAM
Program to Solve a Quadratic Equation
Program to Swap Two Numbers
Program to Find the Factorial of Two Numbers
Program for Fibonacci Series Using Recursion
Sorting Elements of Array in Ascending Order
Program to Print the Sum of Elements of Array
Program to Transpose a Matrix
Program to Reverse a String
Program to Concatenate Two Strings
Program to Append Elements to the List
Program to Delete an Element of List
Program for Linear Search
Program for Binary Search
Program to Perform Time Series Analysis
CONCLUDING REMARKS
Bibliography
Basics of Python Programming:
A Quick Guide for Beginners
Authored by
Krishna Kumar Mohbey
Department of Computer Science
Central University of Rajasthan
Rajasthan, India
&
Malika Acharya
Department of Computer Science
Central University of Rajasthan
Rajasthan, India

BENTHAM SCIENCE PUBLISHERS LTD.

End User License Agreement (for non-institutional, personal use)

This is an agreement between you and Bentham Science Publishers Ltd. Please read this License Agreement carefully before using the ebook/echapter/ejournal (“Work”). Your use of the Work constitutes your agreement to the terms and conditions set forth in this License Agreement. If you do not agree to these terms and conditions then you should not use the Work.

Bentham Science Publishers agrees to grant you a non-exclusive, non-transferable limited license to use the Work subject to and in accordance with the following terms and conditions. This License Agreement is for non-library, personal use only. For a library / institutional / multi user license in respect of the Work, please contact: [email protected].

Usage Rules:

All rights reserved: The Work is the subject of copyright and Bentham Science Publishers either owns the Work (and the copyright in it) or is licensed to distribute the Work. You shall not copy, reproduce, modify, remove, delete, augment, add to, publish, transmit, sell, resell, create derivative works from, or in any way exploit the Work or make the Work available for others to do any of the same, in any form or by any means, in whole or in part, in each case without the prior written permission of Bentham Science Publishers, unless stated otherwise in this License Agreement.You may download a copy of the Work on one occasion to one personal computer (including tablet, laptop, desktop, or other such devices). You may make one back-up copy of the Work to avoid losing it.The unauthorised use or distribution of copyrighted or other proprietary content is illegal and could subject you to liability for substantial money damages. You will be liable for any damage resulting from your misuse of the Work or any violation of this License Agreement, including any infringement by you of copyrights or proprietary rights.

Disclaimer:

Bentham Science Publishers does not guarantee that the information in the Work is error-free, or warrant that it will meet your requirements or that access to the Work will be uninterrupted or error-free. The Work is provided "as is" without warranty of any kind, either express or implied or statutory, including, without limitation, implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the results and performance of the Work is assumed by you. No responsibility is assumed by Bentham Science Publishers, its staff, editors and/or authors for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products instruction, advertisements or ideas contained in the Work.

Limitation of Liability:

In no event will Bentham Science Publishers, its staff, editors and/or authors, be liable for any damages, including, without limitation, special, incidental and/or consequential damages and/or damages for lost data and/or profits arising out of (whether directly or indirectly) the use or inability to use the Work. The entire liability of Bentham Science Publishers shall be limited to the amount actually paid by you for the Work.

General:

Any dispute or claim arising out of or in connection with this License Agreement or the Work (including non-contractual disputes or claims) will be governed by and construed in accordance with the laws of Singapore. Each party agrees that the courts of the state of Singapore shall have exclusive jurisdiction to settle any dispute or claim arising out of or in connection with this License Agreement or the Work (including non-contractual disputes or claims).Your rights under this License Agreement will automatically terminate without notice and without the need for a court order if at any point you breach any terms of this License Agreement. In no event will any delay or failure by Bentham Science Publishers in enforcing your compliance with this License Agreement constitute a waiver of any of its rights.You acknowledge that you have read this License Agreement, and agree to be bound by its terms and conditions. To the extent that any other terms and conditions presented on any website of Bentham Science Publishers conflict with, or are inconsistent with, the terms and conditions set out in this License Agreement, you acknowledge that the terms and conditions set out in this License Agreement shall prevail.

Bentham Science Publishers Pte. Ltd. 80 Robinson Road #02-00 Singapore 068898 Singapore Email: [email protected]

FOREWORD

The fact that Python programming is employed across most fields contributes to its growing popularity in recent years. It is possible to generate software at any level, from the simplest of programs to a fully functional application. Even every company, institution, organization, or researcher uses Python programming in their work, albeit they may do so in various methods. Python makes it possible to develop algorithms that are both effective and efficient as well as to manage more significant amounts of data in today's world. The proposed book covers various Python programming topics, ranging from the fundamentals to more advanced techniques. This book, which serves as a helpful guide to becoming a programmer, will significantly benefit the community.

D. S. Rajput School of Information Technology and Engineering Vellore Institute of Technology Vellore, India

PREFACE

It gives immense pleasure to bring the book "Basics of Python Programming: A Quick Guide for Beginners." The most extensively used programming language today is Python, which also happens to be the most popular programming language. Students enrolled in various classes who can efficiently use this high-level programming language as a problem-solving tool are this Book's target audience. Python is not only employed in the field of computer science; instead, it is used in the development of applications for all areas.

Python programming can be swiftly learned by anybody with a fundamental understanding of computers and the ability to reason logically. Because of this inspiration, we could write this Book clearly and concisely. After reading the Book, you will have a fundamental understanding of how to do programming in Python. We have attempted to present the intricacies of Python in a very colloquial language such that the potential readers require no special expertise to refer to the book. It is apt for beginners as the concepts are explained in simple language with suitable demonstrative examples to facilitate both theory and practical learning.

Our primary goal in writing this book is to provide an approachable resource for beginners new to programming or with limited coding experience. We understand that learning a programming language can be intimidating, especially for those starting from scratch. With "Basics of Python Programming: A Quick Guide for Beginners", we have consciously designed the content to be beginner-friendly, focusing on simplicity and clarity of explanations. We believe that our book's accessible style will empower beginners to grasp the fundamental concepts of Python programming swiftly and confidently.

We recognize that many aspiring programmers are looking for a resource that allows them to learn Python quickly and efficiently. While there are extensive books available that provide in-depth coverage of Python, our book takes a different approach. We have distilled the core concepts and essential components of Python programming into a concise guide that can be absorbed quickly. By focusing on the basics, we aim to provide beginners with a solid foundation in Python programming without overwhelming them with excessive information.

We firmly believe that practical application is critical to mastering Python programming. Therefore, our book emphasizes hands-on learning and incorporates numerous practical examples throughout the chapters. By engaging in coding exercises and mini-projects, readers can actively apply the concepts they learn, solidifying their understanding of Python. Our approach encourages learners to gain practical experience alongside theoretical knowledge, enabling them to build their coding skills from the very beginning.

We firmly believe that "Basics of Python Programming: A Quick Guide for Beginners" offers a unique value proposition to individuals looking to kick-start their journey in Python programming. Its simplicity, efficiency, hands-on approach, clear progression, and supplementary resources set it apart from other books. We hope this book is a valuable tool for learning Python programming and unlocks the door to exciting possibilities.

Krishna Kumar Mohbey Department of Computer Science Central University of Rajasthan Rajasthan, India &
Malika Acharya Department of Computer Science Central University of Rajasthan Rajasthan, India

Introduction to Python

Krishna Kumar Mohbey1,Malika Acharya1
1 Computer Science, Central University of Rajasthan, India

Abstract

Python is an object-oriented programming language that can support a wide range of applications like web development, desktop applications, etc. Its general-purpose programming features make coding easy, comprehensive and readable even for beginners.

Keywords: Development environments, Object-oriented programming, Operating system, Shuffle exchange network, Virtual machine.

INTRODUCTION

Python has grown to be a mainstream language. Its simple syntax and comprehensible code make it a popular general-purpose programming language among developers, engineers, and amateurs with limited programming skills. Its open-source features with a wide variety of libraries facilitate efficient programming. The first chapter of this book provides a brief introduction to Python along with a stepwise guide to installation on Windows and Linux. It will familiarize you with the Python IDE and editors, thus paving your journey to Python programming.

Guido van Rossum, Python's Benevolent Dictator for Life, developed Python in the 1990s. After that, several versions of Python were released. With the end of life of version 2.7, currently, versions 3.6 and 3.9 are widely used. Python is an open-source project maintained by the Python Software Foundation. We can take a tour of the Python universe at www.python.org.

Python is an object-oriented language that, due to its interoperability with existing codes in C and Fortran, gears up to the developer's demands and enhances the programmer's productivity while cutting down the time consumed. Python has become the developer's choice in various fields. For example, some of the prominent areas where Python is used are NASA's Jet Propulsion Laboratory, the Lawrence Livermore National Laboratory, Shell Research Boeing, Industrial Light and Magic, Sony Entertainment, and Procter & Gamble. Python is a high-level language; thus, the programs coded in it are easy and comprehensible. Python codes execute on a virtual machine; hence, a layer of abstraction exists

between the code and the executing platform. Thus, Python is an interpreted language and produces portable codes that are cross-platform executable. Fig. (1) depicts the execution of a simple Python program. Unlike Fortran, Python is a dynamically typed language that uses an interpreter to interpret the representative types at the run time. The layer of abstraction abstracts the underlying optimization from the code. Python binds Fortran and C libraries using an interpreter to perform intensive computation.

Fig. (1)) Execution schematic of Python code.

You must have previously understood various languages like C++, Java, Perl, Scheme, or BASIC. All these languages are high-level languages. Nevertheless, computer hardware understands only low-level language called machine language. So, high-level language needs to be converted into machine language. For this, we have two translators: a compiler and an interpreter. A compiler is a program that translates the entire program into machine language. The high-level program is known as the source code, and the output is machine code. An interpreter is also a program that takes high-level language and converts it into machine code instruction by instruction. Compiled code can be run any number of times without repeated compiling or the source code.

In contrast, interpreted code requires an interpreter and source code every time. Thus, interpreted code makes the programming environment more user-friendly and enhances portability. Every CPU has its machine code, but we can run a high-level language program with the interpreter.

Technical Strengths of Python

Portability

As already discussed, Python is a portable language that requires Byte Code for execution on any platform. An executable byte code converts the source code to platform-independent code. Python consists of a Tkinter toolkit to support the Tk GUI interface so the graphical user interface can run on all GUI's supported platforms without program changes. Python's original, standard implementation was given in ANSI C, making it executable on all major platforms ranging from PDAs to supercomputers.

Object-Oriented

Python is an object-oriented programming language. The language is extensible, i.e., the programs can be extended to C, C++, and Java. It uses a class model to support polymorphism, operator overloading, and other notions. It is a powerful scripting tool for other object-oriented system languages, like C++, Java, and C#. The recent versions of Python also support functional programming. This includes generators, comprehensions, closures, maps, etc.

Community Support

Python community support is quite active and responsive to the user's queries. The community consists of Python creator Guido van Rossum, the Benevolent Dictator for Life (BDFL), and a crew of thousands of workers. Python is more conservative than other languages in terms of changes, i.e., the changes need to be approved by the community, especially BDFL.

Advanced Features

Python provides full support for features of scripting languages like PERL. The scheme facilitates the use of software development tools that are easily found in compiled languages. It is a product of the FLOSS community, i.e., Python is a Free, Libre, and Open-Source Software that assists in knowledge sharing. Some of the salient features of Python are:

Memory Management

Memory allocation and reclamation are no longer the programmer's headache. It adopts automatic memory management allocation and garbage collection so that memory growth and shrink are as per demand. Python considers memory as the private heap. There are two types of allocators for memory management: raw memory allocator and object-specific allocator:

Large system development