Tag Archives: Python

Arithmetic and Comparison Operators

Introduction

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.
>>> 10 // 3
3 >>> 10.0 // 3
3.0 >>>
+x, -x Unary minus and Unary plus (Algebraic signs) -3
~x Bitwise negation ~3 – 4
Result: -8
** Exponentiation 10 ** 3
Result: 1000
or, and, not Boolean Or, Boolean And, Boolean Not (a or b) and c
in “Element of” 1 in [3, 2, 1]
<, <=, >, >=, !=, == The usual comparison operators 2 <= 3
|, &, ^ Bitwise Or, Bitwise And, Bitwise XOR 6 ^ 3
<<, >> Shift Operators 6 << 3

 

Sumber: https://www.python-course.eu/operators.php

Data Types and Variables

Introduction

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

Using the Python Interpreter

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] Bab 1 Perkenalan

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