Python: Difference between revisions

From Halfface
Jump to navigation Jump to search
Line 15: Line 15:
  sys.argv  arguments are passed to the script in the variable sys.argv
  sys.argv  arguments are passed to the script in the variable sys.argv
  #          is used to start a comment
  #          is used to start a comment
operations for numbers
{| class="wikitable"
! Operation
! Symbol
! Example
|-
|Power (exponentiation)
| <code>**</code>
| <code>5 ** 2 == 25</code>
|-
|Multiplication
| <code>*</code>
|<code>2 * 3 == 6</code>
|-
|Division
| <code>/</code>
| <code>14 / 3 == 4</code>
|-
|Remainder (modulo)
| <code>%</code>
| <code>14 % 3 == 2</code>
|-
|Addition
| <code>+</code>
| <code>1 + 2 == 3</code>
|-
|Subtraction
| <code>-</code>
| <code>4 - 3 == 1</code>
|}

Revision as of 21:25, 5 October 2011

links

http://en.wikibooks.org/wiki/Non-Programmer%27s_Tutorial_for_Python_2.6
http://docs.python.org/tutorial

Reference

http://docs.python.org/ref/ref.html

basics

print "Hello, World!"

command called print followed by one argument,which is "Hello, World!". (referred to as a string of characters, or string) Command and its arguments are collectively referred to as a statement,

print "2 + 2 is", 2 + 2

The first argument is the string "2 + 2 is" and the second argument is the mathematical expression 2 + 2, which is commonly referred to as an expression. each of the arguments separated by a comma

sys.argv   arguments are passed to the script in the variable sys.argv
#          is used to start a comment

operations for numbers

Operation Symbol Example
Power (exponentiation) ** 5 ** 2 == 25
Multiplication * 2 * 3 == 6
Division / 14 / 3 == 4
Remainder (modulo) % 14 % 3 == 2
Addition + 1 + 2 == 3
Subtraction - 4 - 3 == 1