background preloader

Raspbian Debian

Facebook Twitter

4. More Control Flow Tools — Python v2.7.5 documentation. Besides the while statement just introduced, Python knows the usual control flow statements known from other languages, with some twists. 4.1. if Statements Perhaps the most well-known statement type is the if statement.

4. More Control Flow Tools — Python v2.7.5 documentation

For example: >>> x = int(raw_input("Please enter an integer: "))Please enter an integer: 42>>> if x < 0:... x = 0... print 'Negative changed to zero'... elif x == 0:... print 'Zero'... elif x == 1:... print 'Single'... else:... print 'More'...More There can be zero or more elif parts, and the else part is optional. 4.2. for Statements The for statement in Python differs a bit from what you may be used to in C or Pascal. >>> # Measure some strings:... words = ['cat', 'window', 'defenestrate']>>> for w in words:... print w, len(w)...cat 3window 6defenestrate 12 If you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected items), it is recommended that you first make a copy. 4.3. >>> range(10)[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Tactical Computer Action (for beginners and their support team) RPi Tutorials.

Back to the Hub.

RPi Tutorials

Community Pages: Tutorials - a list of tutorials. Learn by doing. Guides - a list of informative guides. Make something useful. Projects - a list of community projects. Tasks - for advanced users to collaborate on software tasks. Datasheets - a frambozenier.org documentation project. Education - a place to share your group's project and find useful learning sites.

Community - links to the community elsewhere on the web. ShellCommands. Find default Debian commands based on shell built-in commands and coreutils packages Remember to see man pages.

ShellCommands

It's your first help ! Don't recreate or import man or info pages here. Good informations are: Simple description Some useful examples that are not in man pages You don't find this shell command on your system, see next URL and replace MY_COMMAND by your command ShellToolTricks, PrincipalCommands and coreutils should be merging here alias: Create an alias awk: Find and Replace text within file(s) basename: Return just the file name alone bzip2/bunzip2: Compress or decompress named file(s) echo: Display message on screen egrep: Print lines matching a pattern (same as grep -E) eject: Eject CD-ROM env: Display, set, or remove environment variables exit: Exit the shell (or press Ctrl-D) export: Set an environment variable grep: Print lines matching a pattern groups: Print group names a user is in gzip/gunzip: Compress or decompress named file(s) join: Joins lines on a common field.