adasd

Post on 27-Jan-2016

213 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

qweqwf

TRANSCRIPT

2 ind of numbers in python: integers (int) and floating point (float).

Function print shows anything after it, if it is a number there is no need for ‘ ‘ and a , will separate the values with a space. If it is a string (text) then the ‘ ‘ is needed.

Function type() tells which kind of number we are using.

Function int() or float() will convert a number to that format. In the integer conversion it just take the whole part (eg 3.14 to 3 or 2.89 to 2). Float() just puts a .0 in a whole number.

Python represent float values up to a 15 decimal accuracy.

Arithmetic operators

+ plus (which also serves to join string data); - minu; / divided by; * times; ** power

Division in Python 2:

If one operand is a decimal then the answer is decimal (eg 1.0/3 = 0.3333333333333)

If both operands are integers then the answer is an integer rounded down (eg 1/3=0)

Operator precedence – (), **, *, /, +, -

Variables

Valid variable names correspond to letters, numbers and underscore _

The name has to start with either a letter or an underscore (cant start with a number) and are case sensitive.

= is used to assign a value to the variable; == is used as an equality test.

Variables can be used in expression to assign a value to another value (equations) without the use of ‘’

Operator += takes the value in the variable to the left and sums it to the operator on the right and then it stores it on the variable to the left.

top related