31

Variables and Syntax in Python

Python has all the features of any powerful modern language. If you are familiar with C, C++, or Java, you will find most of its syntax very familiar.

You use variables in Python to represent numbers and strings that might change during the program. Usually variable names are written all in lower case.

In Python, case is significant, and if we write

y = m * x + b       # all lower case

or

Y = m * x + b       # Y differs from y

we mean two different variables: Y and y. This might seem awkward at first, but having the ability to make such distinctions is sometimes very useful. For example, programmers often capitalize symbols that refer to constants:

Get Python Programming with Design Patterns 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.