This chapter covers the various built-in operators, which Python has to offer.
Operators
These operations (operators) can be applied to all numeric types:
Operator
Description
Example
+, –
Addition, Subtraction
10 -3
*, /, %
Multiplication, Division, Modulo
27 % 7
Result: 6
//
Truncation Division (also known as floordivision or floor division)
The result of this division is the integral part of the result, i.e. the fractional part is truncated, if there is any. If both the divident and the divisor are integers, the result will be also an integer. If either the divident or the divisor is a float, the result will be the truncated result as a float.
Even if you think that you know a lot about data types and variables, because you have programmed lower level languages like C, C++ or other similar programming languages, we would recommend to read this chapter. Data types and variables in Python are different in some aspects from other programming languages. There are integers, floating point numbers, strings, and many more, but things are not the same as in C or C++. If you want to use lists in C e.g., you will have to construe the data type list from scratch, i.e. design memory structure and the allocation management. You will have to implement the necessary search and access methods as well. Python provides power data types like lists as a genuine part of the language. Continue reading Data Types and Variables→
With the Python interactive interpreter it is easy to check Python commands. The Python interpreter can be invoked by typing the command “python” without any parameter followed by the “return” key at the shell prompt:
python
Python comes back with the following information:
Python 2.5.2 (r252:60911, Oct 5 2008, 19:29:17)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Once the Python interpreter is started, you can issue any command at the command prompt “>>>”.
The first thing we will do is write the mandatory “Hello World” statement: Continue reading Using the Python Interpreter→
Python merupakan bahasa pemrograman yang mudah dipelajari, dan powerfull. Python mempunyai struktur data tingkat tinggi yang efisien, sederhana dan efektif untuk “object oriented programming”. Bahasa pemrograman python cenderung fokus pada solusi dari masalah daripada sintaks (syntax) dan struktur pemrogramanan.
1.1 Fitur-fitur Python
Sederhana
Mudah dipelajari
Free and opensource
Bahasa tingkat tinggi
Portable
Interpreted
Orientasi object
Extensible
Embeddable
Extensive Libraries
"Bacalah (dengan menyebut) nama Tuhanmu yang menciptakan"