Basic Functions with Python

The following sections cover how Python deals with the raw material of programming: numbers and text.

Numbers

Python can serve as a simple calculator. The syntax it uses is nearly identical to that used for writing spreadsheet formulas. For novices who've created spreadsheets, all of this will seem familiar. The same is true for programmers who've worked with any language that uses an algebraic syntax, such as Pascal, Fortran, Basic, C, or Java.

In Python, you enter a mathematical formula (called an expression) just as you do with spreadsheets, and you're given a resulting value. In programming terms, an expression is a Python statement that returns a value. That value is printed to the console.

Python's expression ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.