Python Made Simple
eBook - ePub

Python Made Simple

Learn Python programming in easy steps with examples

  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Python Made Simple

Learn Python programming in easy steps with examples

About this book

Take tiny steps to enter the big world of data science through this interesting guide Key Features

  • Acquire basic concepts related to python programming
  • Understand the core functionalities of Python Programming
  • Provide the information regarding idle IDE
  • Computational Problem solving in Python
  • Object oriented concepts in Python
  • Database connectivity with Python


Description
In the last few years, python gained popularity and became the first choice of the students, teachers as well as professionals. It is being used in different fields such as education, software development, website development and also in various advanced research. In the field of education it allows students to learn the programming language in an easier and efficient manner. In the information technology field it can be used as a language for creating softwares as well as for web developments. It can be integrated with different platforms like Django. In research, Python programming can be used in simulation or it can be used for machine learning techniques.
The primary goal of this text is to create a pedagogically sound and accessible textbook that emphasises on core concepts of Python programming. The book contains lots of practical examples to show the working of a particular code construct. The book can be very helpful in order to learn the basic and advance concepts of python programming.
In the beginning of the book the focus is on the basic concepts related to core python programming starting from the installation phase of python interpreter to building the concepts for the reader towards python programming. Then the book moves towards the concept of different statements and programming conditions that python programming can handle in an easier manner. It then moves to the concepts related to object oriented programming and at last the reader will get to know about the database connectivity with the python program. What you will learn

  • You can learn the core concept related to python programming
  • You will get to learn how to program in python
  • You can learn how Python programming helps to solve computational problems
  • By reading this book you can learn how to work with python
  • You will get familiarity with the python programming concepts.
  • You will learn how to operate idle IDE and how it can be used to write python program in easier way.
  • Who This Book is For
    The book is intended for anyone who wish to learn python programming language. This book also covers the syllabus of various universities and readers can use this book as a help in their academic education. This book can be used by readers to start with python programming from basics to advanced level even without having any prior knowledge of python programming. Table of Contents
  • Introduction to Python
  • Python Fundamentals
  • Expression and Operators
  • Control Statements
  • Functions
  • List Processing
  • Tuple Processing
  • Dictionary Processing
  • String Processing
  • File Processing
  • Exception Handling
  • Object Oriented Programming
  • Inheritance & Polymorphism
  • Database Design in Python

  • About the Author
    Rydhm Beri teaches in BBK DAV College for Women, Amritsar, as an Assistant Professor, since last three years and has 5 years of experience in the field of education and 3 years of experience in research. Her research interests include MANETs, Cloud computing, IOT, Fog Computing. She has done M.Sc. Computer Science from BBK DAV College for Women, Amritsar and MCA from Lovely Professional University and is currently pursuing Ph.D. in the field of IOT and embedded systems.
    She has a deep knowledge of programming and has worked for different projects in languages like, .Net, Java, PHP and Python. Currently she is working on Python programming and relate it to IOT and Machine learning field.
    She has published 19 research papers out of which 17 are international and 2 are national research papers. She has also been working as a reviewer in conferences and journals. In her leisure time, she likes to attend workshops and conferences and likes to program applications. Blog links: https://rydhmberi.weebly.com/

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Python Made Simple by Rydhm Beri in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming in Python. We have over one million books available in our catalogue for you to explore.

CHAPTER 1

Introduction to Python

Introduction

Computer systems are necessary in almost all fields nowadays. They are used in different fields and help create smart devices such as smart TVs, smart phones, smart home systems, driverless cars, and so on. These systems are gaining popularity by their features and working, as these systems reduce the efforts of human beings. Computers are used in different working environments and have become necessary tools for operations of different organizations. For example, fund managers use computers for analytical trading, architects use computers to make and check building structures, researchers use computers to recreate substantial investigations in material science and science, grocery stores use computers to plan and the calendar used in most homes helps plan the conveyance time and schedules.
The computer coordinates with the hardware and software. Hardware refers to physical segments; for example, chips, keyboard, and monitors, while software refers to operating systems and application programs; for example, Office, Firefox, and so on. The software works on hardware to give helpful functionalities to clients; for example, word processing, web perusing, and gaming. Then again, the hardware gives fundamental support to the software by offering a lot of set of instructions, which the software joins to accomplish the complex functionality.
Writing computer programs is the design of software utilizing a set of essential instructions. Programming language abstract hardware instructions into basic statements, which are easier to understand and handle. Using a programming language, you can compose complex software, accomplishing custom fitted functionalities by a blend of fundamental statements. This is a definitive method for using a computer and is essential while existing software neglects to fulfill the prerequisite; for example, the need of a computer to solve an equations or to simulate specific experiments in an engineering discipline.

Structure

  • Relation between programming languages
  • Computational problem solving
  • Introduction to Python
  • History of the Python programming language
  • Features of Python
  • Execution of a Python program
  • Memory management in Python
  • Debugging

Objective

  • Understanding the core concept of programming in Python
  • Understanding how Python programming can be used to solve computation problem solving
  • Knowing about the history and features offered by the Python programming language
  • Understanding the concept of memory management in Python
  • Knowing about the process of debugging in Python
  • Understanding how to run and execute Python programs

Relation between programming languages

Though each programming language is different, they can be related along some dimensions. These dimensions are shown in the following figure:
Figure 1.1: Programming language relation

Low-level versus high-level language

A low-level programming language manages the computer hardware segments and constraints. It provides little or no abstraction from the computer’s instruction set architecture commands or capacities in a programming language map closely to the processor instructions. The basic role of the low-level language is to work, manage and control the computing hardware components. Program and applications written in low-level languages are directly executed on the computing equipment with no translation or interpretation. A program written in a low-level language tends to relatively non-portable, primarily in view of the close connection between the language and the hardware architecture. Some of the low-level languages are machine and assembly languages; these are termed as the first generation and second generation languages, respectively.
A high-level language is a programming language intended to improve computer-programming languages. A high-level language is any programming language that empowers advancement of a program in a substantially more user-friendly programming context and is commonly autonomous of the computer’s hardware architecture. A high-level language has a higher level of abstraction from the computer and concentrates more on the programming logic rather than the underlying hardware components such as memory addressing register utilization. To execute the code of a high-level language on the computer system, you need a convertor that changes the high-level language code to the low-level language code (as the computer system only understands a low-level language). With the assistance of high-level languages, you can write the applications that are compact over the various platforms and is autonomous of any architecture. Some of the examples of high-level languages are C++, Java, Python, and so on.

General-purpose language versus domain-specific language

The general-purpose programming language is used to write applications in numerous application domains. On the other side, a general-purpose programming language is restricted to use for a specific type of a computer system or specialized application. In many ways, a general-purpose language only has this status because it does not include language constructs designed to be used within a specific application domain. The general-purpose language is used to solve a variety of problems in an easy and efficient manner. The examples of general-purpose programming languages are C, C++, Java, C#, Python, and so on.
A domain-specific language is a specialized computer language designed for a specific task. In other words, a domain-specific language is a computer programming language used to solve a specific type of problem. A domain-specific language can also be defined as the language targeted towards making certain kind of things possible but does not do everything that other languages might. A domain-specific language is created specifically to solve problems in a particular domain and is not intended to be able to solve problems outside of it. It may be developed to meet the needs of a particular platform, system, toolset, software problem, industry, or business challenge that cannot be effectively addressed using mainstream languages. There is a wide variety of DSLs, ranging from widely used languages for common domains, such as HTML for web pages, to languages used by only one or a few pieces of software such as Lisp, Prolog, and so on.

Compiled languages versus interpreted languages

The compiled languages are computer-programming languages in which the translator known as the compiler is used to translate the code written in some programming language to the native code or machine language code so that the converted code can easily be executed by the computer system. The programming code is termed as source code, while the native or machine code is termed object code. The source code may be written in some high-level language and native code or machine code is low-level language code. By native code, we mean that this code requires some processing before directly executing it on the computer system while the machine language code is directly executed by the machine without the requirement of any processing. The processing required by the native code may be further converted to the machine code or maybe some linking task. Most of the compilers nowadays convert the programming code into the native code to provide the platform independence functionality to the code. The compiler converts the source code to the target code by scanning the whole program line by line and after that creates an object code file of a low-level language that is used by another processor for further processing, or it is executed many times without repeating the compilation process. Some of the examples of compiled languages are C, C++, C#, Objective-C, Scala, and so on. Compiled programs run faster as compared to interpreted programs.
The interpreted languages are computer-programming languages in which the translator known as an interpreter is used to translate the code written in some programming language to the machine language code so that the converted code can easily be executed by the computer system. Unlike compiled languages, an interpreted language’s translation does not happen beforehand. The translation occurs at the same time as the program is being executed. Interpreted languages have major advantages such as they are portable, which means they can run on different operating systems and platforms. Because they are translated on the spot, they are going to be optimized for the system on which they are being run. This means there are no middle steps, less memory space is required for conversion of the object code, and there is no need to worry about platform-specific code. The interpreter converts the source code into the machine code each time you run the program, one line at a time. It starts interpreting each instruction immediately on execution, which means that the resulting program runs slower than a compiled program. Interpreted languages are especially helpful for reviewing, running, and testing an application’s functionality during the development because they are able to execute high-level programs immediately and generate helpful error reports. They allow programmers to make small systematic changes during the development process, incrementally, which complement a step-by-step process for adding and then testing smaller sections of an application. Some of the examples of interpreted languages are Java, PHP, Perl, Python, and so on.

Computational problem solving

Computational problem solving is a step by step procedure used to solve the real-world problems using the computer system. In other words, computational problem solving is a process in which some theoretical and experimental aspects are used to create a computer-based model that might be able to solve the particular problem. After creation, these models might be used to simulate the behavior of objects and relate the results to the objects that exist in the real world. The process of computational problem solving is most often applied in cases where the physical experiment is difficult, expensive or impossible. In the process of computational problem solving, the problem to be solved is given as the input to the system, and in return, the results are provided by the computer systems, which satisfy some properties. The field of algorithm studies the method of solving a computational problem efficiently. Before solving the problem with the help of computers, the generalized algorithm is created.

Process of solving computational problems

The process of solving a computational problem solving does not begin with writing a computer program. In fact, a lot of creative work must be done before the first line of a program can be written. It is a process with programming being only one of the steps. Before a program is written, a design for the program must be developed. Before a design can be developed, the problem to be solved must be well understood. Once it is written, the program must be thoroughly tested. Therefore, the process of computational problem solving consists of series of steps to be performed to solve a particular problem using computer systems. The following diagram shows the steps involved in the process of computational problem solving:
Figure 1.2: Process of computational problem solving

Problem solving

The problem analysis can be defined as a process of understanding the problem and the users need to relate to the problem. It is also considered a process of proposing a solution to that problem. A problem analysis explores a problem to enable the developer to see all the problems so that it can prescribe practical solutions for solving it. Problem analysis is a set of analytic tasks intended to increase the designer’s understanding of an unbalanced solution for the sake of designing a change to the circumstances that will have better equalization.
It is important to note that:
  • Designing is not performed at this stage.
  • Solutions to the problems are not found in this stage.
  • The current situation is analyzed and other situations that can be preferred need to be mentioned.
The main aim of problem analysis is to gain a better understanding of the problem before the development of the solution begins. Problem analysis is mainly done in the following sections.

Understanding the problem

The first step is to examine the problem carefully. Once the problem is clearly understood, the fundamental computational issues for solving the problem can be determined. A single problem may have many different solutions, but they will all have something in common. Therefore, you must try to analyze which program will be required to do the particular task in an optimized manner.
For instance, in the event that we were approached to compose a calculator program, we could pick a wide range of ways for the user to enter calculations such as entering equations, pressing buttons or even writing them on the screen. But if the software cannot add up correctly then it will not solve the problem. Subsequently, our initial couple of prerequisites must be as follows:
  • The user can enter sums (we do not care how they do this).
  • The program will then evaluate those sums correctly and display the result for the user.
    We also need to decide what sort of sums our calculator will be required to evaluate. Again, we have a fair amount of choice. We could be ambitious and ask it to solve simultaneous equations or complex expressions. Therefore, the third requirement is as follows:
  • The calculator must be able to evaluate sums made up of two whole numbers (integer operands) and one addition (+), subtraction (-), multiplication (*) or division (/) sign (operator).

Specification

The second step is to then look at the list of requirements and decide exactly what your solution should do to fulfill them. Besides clearly understanding a computational problem, you must know what constitutes a solution. For some problems, there is only one solution. For others, there may be a number (or infinite number) of solutions. Here, the main aim is to decide the best solution to solve the problem. The best solution is the one with the shortest number of steps.
For instance, a simple calculator allows the user to input some numbers, perform only basic arithmetic operations, and print the obtained results on the screen. We must note down the details of all these operations in this phase.
Therefore, we need to decide which methods we need to write the basic operations. We need to note down all the other functionalities a calculator program can perform, which are as follows:
  • When the software of a calculator starts, it may show a welcome message on the screen and some simple instructions or manual instructions to use the calculator software.
  • The software program then displays the prompt sign ([number]>) and the user needs to input the first number followed by the Enter key.
  • The software program displays the prompt sign and the user needs to input the type of operator that needs to be applied to the...

Table of contents

  1. Cover Page
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. About the Author
  6. Acknowledgements
  7. Preface
  8. Errata
  9. Table of Contents
  10. 1. Introduction to Python
  11. 2. Python Fundamentals
  12. 3. Expressions and Operators
  13. 4. Control Statements
  14. 5. Functions
  15. 6. List Processing
  16. 7. Tuple Processing
  17. 8. Dictionary Processing
  18. 9. String Processing
  19. 10. File Processing
  20. 11. Exception Handling
  21. 12. Object-oriented Programming (OOP)
  22. 13. Inheritance and Polymorphism
  23. 14. Database Design in Python