13.07.2015 Views

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

Analysis of Structures - Baustatik-Info-Server

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.3. OPERATORS Page 15(plus and minus). Unary operators will always be applied first. To change the standard precedence <strong>of</strong> theoperators we use like in mathematics parenthesis to dictate the way a formula should be evaluated.2.3.1 Unary OperatorsUnary operators are working only on one value, therefor unary. In Python there are three unary operatorsavailable.Operator Comment Example+ plus operator a = 2 >>> x = +a >>> +2- minus operator a = 2 >>> x = -a >>> -2˜ bitwise inversion a = 2 >>> x = ˜a >>> -3The bitwise inversion shows the internal representation <strong>of</strong> negative numbers. A negative number isrepresented by the so called b-complement <strong>of</strong> a number. This is the complement, i.e. the bitwise invertednumber plus 1. So we get−a =∼ a + 1 or ∼ a = −(a + 1) (2.1)2.3.2 Arithmetic OperatorsPython <strong>of</strong>fers the following arithmetic operators. You should be careful with the usage <strong>of</strong> data typesespecially within divisions. If you use integers, the result generally will be truncated. 1Operator Comment Example+ sum operator x = 2+3 >>> 5- substraction operator x = 4-2 >>> 2* product operator x = 2*4 >>> 8/ division operator x = 9/2 >>> 4x = 9./2. >>> 4.5** power operator x = a**2% modulo operator x = a%2// integer division operator x = a//22.3.3 Bit OperatorsLike in C bit operators can be easily be used to manipulate a number’s bits. The following operators areavailable 21 The exception <strong>of</strong> the power operator all the arithmetic operators are used with the same symbol like in C. In C there is nopower operator available.2 Python’s bit operators are exactly the some as the C bit operators.2.12.2011

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!