Python
A Step-by-Step Guide to Learn, in an Easy Way, the Fundamentals of Python Programming Language
st Edition
2020
By
John Bach
For information contact :
(alabamamond@gmail.com, memlnc)
http://www.memlnc.com
First Edition: 2020
Python 3
Copyright 2020 by John Bach
"Programming isn't about what you know; it's about what you can figure out. - Chris Pine
- Installing Python
- Your first Python program
- Built-in data types
- Generators
- Strings
- Regular expressions
- Closures and generators
- Classes and iterators
- More on iterators
- Testing
- Refactoring
- Files
- XML
- Serializing Python Objects
- HTTP and web services
- Example: porting chardet to Python 3
- Creating library packages
- Porting code to Python 3 with 2to3
- Special method names
- where to go
- Troubleshooting
- About the book
- About translation
- Output
Install / Uninstall: Applications Supported by Canonical
When you first launch Add / Remove, a list of applications is displayed by category. Some are already installed, but most are not. The repository contains over 10,000 applications, so you can apply various filters to view smaller parts of the repository. The default filter , "Canonical-maintained applications" , shows a small subset of the total number of applications, only those officially supported by Canonical , which creates and maintains Ubuntu Linux.
Install / uninstall: all Open Source applications
Python 3 is not supported by Canonical, so first select "All Open Source applications" from the filter drop-down menu.
Install / Uninstall: Search for "python 3"
After switching the filter to show all open applications, immediately use the search bar to find "python 3".
Install / Uninstall: Select Python 3.0 Package
Now the list of applications has been reduced to those that match the query "python 3". There are two packages to note. The first is "Python (v3.0)". It contains the actual Python interpreter.
Install / Uninstall: Selecting the IDLE Package for Python 3.0
The second package you need is directly above the first one - "IDLE (using Python-3.0)". It is a graphical Python shell that you will use throughout this book.
After you check these two packages, click the Apply Changes button to continue.
Install / uninstall: apply changes
The package manager will ask you to confirm that you want to install two packages - "IDLE (using Python-3.0)" and "Python (v3.0)".
Click the "Apply" button to continue.
Install / uninstall: download progress bar
The package manager will show a progress bar while downloading the required packages from the Canonical online repository.
Install / uninstall: installation progress bar
After downloading the packages, the package manager will automatically start installing them.
Install / uninstall: new apps installed
If everything went well, the package manager will confirm that both packages were installed successfully. From here, you can start the Python shell by double-clicking on "IDLE" or by clicking "Close" to exit the package manager.
You can always start the Python shell from the Applications menu, Programming submenu, by choosing IDLE.
A graphical interactive Python shell for Linux
The Python shell is where you spend most of your time exploring Python. All examples in this book assume that you know how to find the Python shell.
Go to using the Python shell . |
|
Installation on other platforms
Python 3 is available on many different platforms. In particular, it is available on almost any Linux, BSD and Solaris distribution . For example, Re dHat Linux uses the yum package manager ; in FreeBSD its ports and packages collection ; Solaris has pkgadd with friends. A web search for "Python 3" + your operating system name will quickly show you if the appropriate Python 3 package is available and how to install it.
Using the Python shell
The Python Shell is where you can explore Python syntax, get online command help, and debug small programs. The Python graphical shell , IDLE , also includes a nice text editor that supports Python syntax highlighting. If you don't have your favorite text editor yet, IDLE is worth a try.
First things first, the Python shell itself is a wonderful interactive playground for playing with the language. Throughout the book, you'll see examples like this:
>>> 1 + 1 2
The first three angle brackets - >>> - denote a Python shell prompt. You do not need to enter it. This is just to show you that this example should run in the Python shell.
1 + 1 is what you enter. In the shell, you can enter any valid Python expression or command. Don't be shy, she won't bite! The worst thing that can happen is an error message. Commands are executed immediately (as soon as you press Enter ), expressions are evaluated immediately too, and the shell prints the result.
2 - the result of evaluating this expression. As expected, 1 + 1 is a valid Python expression. The result is of course 2 .
Now let's try another example.
>>> print ( 'Hello world!' ) Hello world !
Pretty simple, right? But there are many more things you can do in the Python shell! If you get stuck somewhere, suddenly forget a command or what arguments you need to pass to a function, you can always call the online help in the Python shell. Just type help and press Enter .
Next page