eBook - ePub
Python for Beginners
Learn It as Easy as Pie
Yatin Bayya
This is a test
Partager le livre
- English
- ePUB (adapté aux mobiles)
- Disponible sur iOS et Android
eBook - ePub
Python for Beginners
Learn It as Easy as Pie
Yatin Bayya
DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations
Ă propos de ce livre
Whether you are an absolute beginner or an experienced programmer, learn Python programming in a simple, concise, and straightforward manner. Learn to build four smashing projects: a calculator, a drawing app, a login system, and a notes app. This book will walk you through the first steps of becoming a programmer as easy as pie.
Foire aux questions
Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier lâabonnement ». Câest aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via lâapplication. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă la bibliothĂšque et Ă toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode dâabonnement : avec lâabonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă 12 mois dâabonnement mensuel.
Quâest-ce que Perlego ?
Nous sommes un service dâabonnement Ă des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă toute une bibliothĂšque pour un prix infĂ©rieur Ă celui dâun seul livre par mois. Avec plus dâun million de livres sur plus de 1 000 sujets, nous avons ce quâil vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Ăcouter sur votre prochain livre pour voir si vous pouvez lâĂ©couter. Lâoutil Ăcouter lit le texte Ă haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, lâaccĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Python for Beginners est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă Python for Beginners par Yatin Bayya en format PDF et/ou ePUB ainsi quâĂ dâautres livres populaires dans Informatica et Informatica generale. Nous disposons de plus dâun million dâouvrages Ă dĂ©couvrir dans notre catalogue.
Informations
CHAPTER 1:
Introduction
The digital age is revolutionizing the world in terms of technology and software. Programmers provide the most useful software, enhance the world, and communicate with computers by thinking creatively.
Python is the language of choice for many of these next-generation problem-solvers. It is a powerful language whose explicit syntax allows new programmers to focus on developing software. As of 2020, Python is one of the most popular programming languages and ranks consistently at the top.
This book teaches the essential concepts and syntax of Python 3 and provides guidance for implementation with tutorials on building projects.
Getting Started
Without further ado, here is how to install Python 3 and get started creating applications.
To begin the installation, go to the âDownloadsâ page on the Python website (https://www.python.org/downloads). Select the latest stable download version (versions 3.x) for your operating system. Open the file after the download completes.
On Windows:
In this window, check âAdd Python 3.8 to PATHâ and click âInstall Now.â
On macOS:
In this window, go through all the steps until âInstallation Typeâ and then click on the button âCustomizeâ and make sure that everything is selected as shown in the preceding window. After you have confirmed, everything is selected, finish the installation.
Once completed, search for the Integrated Development and Learning Environment (IDLE) application which is installed with Python earlier:
This is known as an interpreter, which evaluates and converts the code typed in there on the fly. Python is a high-level programming language that is easier for developers to read. In contrast, the computer understands the low-level machine code that is more difficult to read. The solution for the computer to understand Python is to convert this high-level code into machine code. There are several implementations (ways of converting code) to achieve this:
The first option is to use a compiler that translates the code into machine code and then runs it. The machine code created by the compiler is executable, which can be run on other computers but is not fully cross-platform compatible. The executable cannot run on any operating system unless the source code is shared, and each operating system has its own version.
Another way is to use an interpreter that translates the code on the fly and then runs it, rather than saving a separate file. The downside is that when the application needs to run on someone elseâs machine, the source code is exposed. Additionally, the client will need an interpreter to run the code. This approach is often slower than compilers because it requires to recompile every single time.
Both options have advantages and disadvantages, but the intermediate approach or bytecode combines their benefits. A virtual machine converts the source code to the lowest level possible while remaining cross-platform compatible. When running it, the compiler translates it into machine code. This code is not executed by the CPU but rather by the Python Virtual Machine (PVM). Python takes this approach, but its process is still, primarily âinterpreted,â and it also has some compilations under the intermediate approach or bytecode.
In the IDLE menu bar, click on the âFileâ button and then on the âNew Fileâ option:
This will open a blank window for Python code. The first program will be a simple program that displays âHello Worldâ when executed:
Click on the âRunâ option and then âRun Now,â and save the file to execute the code. Now it should show the printed result of âHello World,â where commands execute and receive a result. âPrintâ is a built-in function. A function is a block of code that can be executed by using its name. Pythonâs source code defines a function to display a message and calls it to print. Essentially, the âprintâ function code outputs and displays a string (text).
The âprintâ functionâs syntax is as follows: print, parentheses, opening single/double quote, the message, the matching closing quote, closing parentheses. The message in the function must be enclosed in quotes because that differentiates code from text. Adding comments to code helps developers from a readability perspective, but the interpreter ignores them:
The octothorpe (#) denotes a comment, and all the text on the right-hand side is commented outâor not executedâand acts like plain text, doing nothing.
The code is syntax highlighted. Meaning it color codes keywords and certain distinct parts of the code, in IDLE and other text editors or integrated development environments (IDEs). Although it is possible to type Python code in any program that edits text, text editors and IDEs provide niche features. A text editor is simply a program that allows the user to type text with some syntax highlighting ability, while an IDE is similar but must also offer feature-rich programming tools for the developer.
Any text editor or IDE can be used for the purposes of this book, but, PyCharm is recommended.
Installing and Using PyCharm
PyCharm is an application that executes Python programs. Download the âCommunityâ version (https://www.jetbrains.com/pycharm/download) and follow through the installation process. Once it is installed, go through these steps:
- Create a Project.
- Give it a name.
- Be sure to uncheck the âCreate a main.py welcome script.â
- In the project:
- Check whether the interpreter is selected there:
- On Windows:
Click âFileâ on the menu and go to âSettings.â
- On macOS:
Click on âPyCharmâ on the menu and go to âPreferences.â
- Search for the âPython Interpreterâ and open it.
- Select the Python version installed:
- On Windows:
- Create a new Python file and give it a name.
- Open that file.
- In the file, call or use the print function to display âHello World.â
- Right-click and run the application.
- âHello Worldâ should appear in the bottom window.
- Check whether the interpreter is selected there:
It is recommended to create a new Project for every program you write. Each project should have related files that all come together to create a program.
Using the Interpreter
When IDLE is opened without choosing a file, it will open an interpreter, which can also be accessed by typing in âpythonâ to the Terminal (macOS/Linux) or Command Prompt (Windows) application, which should be already on your system.
The Python code, entered in the interpreter, will be evaluated or executed on the fly:
As seen in the last page, the code is executed on the fly and the output is given immediately.
CHAPTER 2:
Variables and Data
A variable is a name with an ...