Home arrow Python arrow Page 7 - Python 101 (part 2): If Wishes Were Pythons

Tying Up The Loose Ends - Python

Begin your tour of Python with a look at its number and stringtypes, together with examples of how they can be used in simple Pythonprograms. Along the way, you'll also learn how to build conditionalexpressions, slice and dice strings, and accept user input from the commandline

  1. Python 101 (part 2): If Wishes Were Pythons
  2. Tax Evasion
  3. Q
  4. Sliced And Diced
  5. Comparing Apples And Oranges
  6. If Only...
  7. Tying Up The Loose Ends
  8. Cookie-Cutter Code
  9. Time For Lunch
By: Vikram Vaswani, (c) Melonfire
Rating: starstarstarstarstar / 3
May 31, 2001

print this article


In addition to the "if" statement, Python also allows you a couple of variants - the first is the "if-else" statement, which allows you to execute different blocks of code depending on whether the expression is evaluated as true or false.

The structure of an "if-else" statement looks like this:

if condition: do this! else: do this!
In this case, if the conditional expression evaluates as false, all statements within the indented "else" block will be executed. Modifying the example above, we have

#!/usr/bin/python # ask for a number alpha = input("Gimme a number! ") # ask for another number beta = input("Gimme another number! ") # check if alpha == beta: print ("Can't you read, moron? I need two *different* numbers!") else: print ("Finally! A user with active brain cells!");

>>> More Python Articles          >>> More By Vikram Vaswani, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates


Dev Shed Tutorial Topics: