Difference between revisions of "Python"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) |
Rafahsolis (talk | contribs) |
||
| Line 45: | Line 45: | ||
or | or | ||
not</nowiki> | not</nowiki> | ||
| + | |||
| + | === Membership operators === | ||
| + | in<br /> | ||
| + | not in<br /> | ||
| + | |||
| + | == Variables == | ||
| + | === Numbers === | ||
| + | === String === | ||
| + | Strings can be subset, | ||
| + | <source lang="python"> | ||
| + | MyString = "Hello world" | ||
| + | MyString[0:4]</source> | ||
| + | Hel | ||
| + | === Lists === | ||
| + | === Tuple === | ||
| + | === Dictionary === | ||
| + | Key - Value pairs, | ||
Revision as of 08:54, 5 April 2015
Indentation
Python is an indented language, so the code indentation matters. A good practice is to indent with 4 spaces (if you mix spaces and tabs the code won't work.
Operators
Arithmetic
+ Addition - Substraction * Multiplication / Division ** Power % Reminder // Floor division (Reminder is removed)
Comparison
== Equal != Not equal > Greater >= Greater or equal < Smaller <= Smaller or equal <> Similar to !=
Assignment
= Simple assignment += Add and as -= Substract and assignment *= Multiply and assignment /= Divide and assignment %= Modulus and assignment **= Exponent and assignment //= Floor Divisionn and assignment
Bitwise operators
They perform operations on binary terms. a= 8 → 100; b= 9 → 101; a & b → 100
$ Binary AND | Binary OR ^ Binary XOR ~ Binary complement << Binary left shift >> Binary right shift
Logic
and or not
Membership operators
in
not in
Variables
Numbers
String
Strings can be subset,
MyString = "Hello world"
MyString[0:4]
Hel
Lists
Tuple
Dictionary
Key - Value pairs,