Python 101 (part 1): Snake Eyes - Adding Things Up
(Page 6 of 6 )
Here's another program, this one performing an arithmetic operation on a variable and displaying the result.
>>> num1 = 10
>>> num2 = 5
>>> num3 = num1 + num2
>>> num3
15
>>>
Note that Python also allows you to display the value of a variable (in the command
line interpreter only) by stating the variable name without a preceding print() function call.
Finally, Python also allows you to simultaneously assign a value to multiple variables - check it out.
>>> huey = dewey = louie = 75
>>> dewey
75
>>> louie
75
>>>
And that's about it for this introduction to Python. In this article, I've provided
a brief history of Python, and explained some of the features which make it so popular among discerning developers. I've also discussed the two methods available to run a Python program, demonstrated the print() function, and offered some insight into the rules governing Python variables.
In the next article, I'll be delving deeper into Python's data structures and built-in objects - numbers and - together with a closer look at the various arithmetic and comparison operators. See you then!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |