Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "AmigaOS Manual: Python Elements of Python"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
(Added table of Bitwise Operations and table of Logical Operations.)
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
= Data types =
 
= Data types =
   
== Numeric types ==
+
== Numbers ==
 
== Tuplets and lists ==
 
   
 
== Strings ==
 
== Strings ==
   
== Dictionaries ==
+
== Arrays ==
  +
  +
Python has four types of arrays (data collections) with different properties:
  +
* '''Lists''': duplicate members are allowed, lists are ordered and indexed, and their content can be changed.
  +
* '''Tuples''': duplicate members are allowed, tuples are ordered and indexed, and their content cannot be changed.
  +
* '''Sets''': duplicate members are not allowed, sets are unordered and unindexed, and their content cannot be changed.
  +
* '''Dictionaries''': duplicate members are not allowed, dictionaries are unordered but indexed, and their content can be changed.
  +
  +
=== Lists ===
  +
  +
Python has the following functions for the lists
  +
{| class="wikitable"
  +
! style="text-align:left;" | Function
  +
! style="text-align:left;" | Explanation
  +
|-
  +
| '''cmp''' ( <firstList>, <secondList> ) || Compare lists <firstList> and <secondList>.
  +
|-
  +
| '''len''' ( <list> ) || Get the number of elements on the list <list>. See [[AmigaOS_Manual:_Python_Functions#len.28.29|len()]] for more information.
  +
|-
  +
| '''max''' ( <list> ) || Get the maximum valued element on the list <list>. See [[AmigaOS_Manual:_Python_Functions#max.28.29|max()]] for more information.
  +
|-
  +
| '''min''' ( <list> ) || Get the minimum valued element on the list <list>. See [[AmigaOS_Manual:_Python_Functions#min.28.29|min()]] for more information.
  +
|-
  +
| '''list''' ( <tuple> ) || Convert the tuple <tuple> into a list. See [[AmigaOS_Manual:_Python_Functions#list.28.29|list()]] for more information.
  +
|}
  +
  +
and the following methods for the list objects
  +
{| class="wikitable"
  +
! style="text-align:left;" | Method
  +
! style="text-align:left;" | Explanation
  +
|-
  +
| <list>.'''append''' ( <object> ) || Append an object <object> to the list <list>.
  +
|-
  +
| <list>.'''count''' ( <object> ) || Count how many times object <object> appears on the list <list>.
  +
|-
  +
| <list>.'''extend''' ( <secondList> ) || Append list <secondList> into the list <list>.
  +
|-
  +
| <list>.'''index''' ( <object> ) || Find the first appearance of the object <object> on the list.
  +
|-
  +
| <list>.'''insert''' ( <index>, <object> ) || Insert object <object> into the list <list> at offset <index>.
  +
|-
  +
| <list>.'''pop''' ( [<index>] ) || Remove and return the last object from the list <list> or an object at the supplied offset.
  +
|-
  +
| <list>.'''remove''' ( <object> ) || Remove object <object> from the list <list>.
  +
|-
  +
| <list>.'''reverse''' () || Reverses the list <list> order.
  +
|-
  +
| <list>.'''sort''' ( [<function>] ) || Sort the list <list>. Uses the optional compare function <function>, if given.
  +
|}
  +
  +
=== Tuples ===
  +
  +
=== Sets ===
  +
  +
=== Dictionaries ===
   
 
== Files ==
 
== Files ==
   
  +
= Objects =
== Other data types ==
 
   
 
= Operators =
 
= Operators =
   
 
== Arithmetic operators ==
 
== Arithmetic operators ==
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Operator !! Name !! Explanation
 
! Operator !! Name !! Explanation
Line 35: Line 86:
 
|}
 
|}
   
  +
== Comparison operators ==
== Bitwise Operations on Integer Types ==
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Operator !! Name !! Explanation
 
! Operator !! Name !! Explanation
 
|-
 
|-
  +
| < || Less Than || Returns whether x is less than y. All comparison operators return 1 for true and 0 for false. This is equivalent to the special variables '''True''' and '''False''' respectively. Note the capitalization of these variables' names.
| << || Left Shift || Shifts the bits of the number to the left by the number of bits specified.
 
 
|-
 
|-
  +
| > || Greater Than || Returns whether x is greater than y.
| >> || Right Shift || Shifts the bits of the number to the right by the number of bits specified.
 
 
|-
 
|-
  +
| <= || Less Than or Equal To || Returns whether x is less than or equal to y.
| & || Bitwise AND || Bitwise AND of the numbers.
 
 
|-
 
|-
  +
| >= || Greater Than or Equal To || Returns whether x is greater than or equal to y.
| | || Bitwise OR || Bitwise OR of the numbers.
 
 
|-
 
|-
| ^ || Bitwise XOR || Bitwise XOR of the numbers.
+
| == || Equal To || Compares if the objects are equal.
 
|-
 
|-
| ~ || Bitwise Invert || The bitwise inversion of x.
+
| != || Not Equal To || Compares if the objects are not equal.
 
|}
 
|}
   
== Logical Operators ==
+
== Assignment Operators ==
 
{| class="wikitable"
 
{| class="wikitable"
 
! Operator !! Name !! Explanation
 
! Operator !! Name !! Explanation
 
|-
 
|-
  +
| = || Assignment || Assigns values from right side operands to left side operand.
| not || Boolean NOT || If x is '''True''', it returns '''False'''. If x is '''False''', it returns '''True'''.
 
 
|-
 
|-
  +
| += || Addition and assignment || Adds right operand to the left operand and assigns the result to left operand.
| and || Boolean AND || x and y returns '''False''' if x is '''False''', else it returns evaluation of y.
 
 
|-
 
|-
  +
| -= || Subtraction and assignment || Subtracts right operand from the left operand and assigns the result to left operand.
| or || Boolean OR || If x is '''True''', it returns '''True''', else it returns evaluation of y.
 
|}
 
 
== Comparison operators ==
 
 
{| class="wikitable"
 
! Operator !! Name !! Explanation
 
 
|-
 
|-
  +
| *= || Multiplication and assignment || Multiplies right operand with the left operand and assigns the result to left operand.
| < || Less Than || Returns whether x is less than y. All comparison operators return 1 for true and 0 for false. This is equivalent to the special variables '''True''' and '''False''' respectively. Note the capitalization of these variables' names.
 
 
|-
 
|-
  +
| /= || Division and assignment || Divides left operand with the right operand and assigns the result to left operand.
| > || Greater Than || Returns whether x is greater than y.
 
 
|-
 
|-
| <= || Less Than or Equal To || Returns whether x is less than or equal to y.
+
| %= || Modulo and assignment || Takes modulus using two operands and assigns the result to left operand.
 
|-
 
|-
  +
| **= || Power of and assignment || Performs exponential (power) calculation on operators and assigns value to the left operand.
| >= || Greater Than or Equal To || Returns whether x is greater than or equal to y.
 
 
|-
 
|-
  +
| //= || Floor division and assignment || Performs floor division on operators and assigns value to the left operand.
| == || Equal To || Compares if the objects are equal.
 
|-
 
| != || Not Equal To || Compares if the objects are not equal.
 
 
|}
 
|}
   
== Boolean operators ==
+
== Logical Operators ==
 
 
{| class="wikitable"
 
{| class="wikitable"
 
! Operator !! Name !! Explanation
 
! Operator !! Name !! Explanation
Line 93: Line 135:
 
|}
 
|}
   
  +
== Bitwise Operations on Integer Types ==
== Conditional operators ==
 
  +
{| class="wikitable"
  +
! Operator !! Name !! Explanation
  +
|-
  +
| << || Left Shift || Shifts the bits of the number to the left by the number of bits specified.
  +
|-
  +
| >> || Right Shift || Shifts the bits of the number to the right by the number of bits specified.
  +
|-
  +
| & || Bitwise AND || Bitwise AND of the numbers.
  +
|-
  +
| <nowiki>|</nowiki> || Bitwise OR || Bitwise OR of the numbers.
  +
|-
  +
| ^ || Bitwise XOR || Bitwise XOR of the numbers.
  +
|-
  +
| ~ || Bitwise Invert || The bitwise inversion of x.
  +
|}
  +
  +
== Membership Operators ==
  +
== Identity Operators ==
   
 
= Comments =
 
= Comments =
   
= Code blocks =
+
= Indentation =
= Interprocess Communication Through ARexx Ports =
 

Latest revision as of 13:06, 5 December 2022

Data types

Numbers

Strings

Arrays

Python has four types of arrays (data collections) with different properties:

  • Lists: duplicate members are allowed, lists are ordered and indexed, and their content can be changed.
  • Tuples: duplicate members are allowed, tuples are ordered and indexed, and their content cannot be changed.
  • Sets: duplicate members are not allowed, sets are unordered and unindexed, and their content cannot be changed.
  • Dictionaries: duplicate members are not allowed, dictionaries are unordered but indexed, and their content can be changed.

Lists

Python has the following functions for the lists

Function Explanation
cmp ( <firstList>, <secondList> ) Compare lists <firstList> and <secondList>.
len ( <list> ) Get the number of elements on the list <list>. See len() for more information.
max ( <list> ) Get the maximum valued element on the list <list>. See max() for more information.
min ( <list> ) Get the minimum valued element on the list <list>. See min() for more information.
list ( <tuple> ) Convert the tuple <tuple> into a list. See list() for more information.

and the following methods for the list objects

Method Explanation
<list>.append ( <object> ) Append an object <object> to the list <list>.
<list>.count ( <object> ) Count how many times object <object> appears on the list <list>.
<list>.extend ( <secondList> ) Append list <secondList> into the list <list>.
<list>.index ( <object> ) Find the first appearance of the object <object> on the list.
<list>.insert ( <index>, <object> ) Insert object <object> into the list <list> at offset <index>.
<list>.pop ( [<index>] ) Remove and return the last object from the list <list> or an object at the supplied offset.
<list>.remove ( <object> ) Remove object <object> from the list <list>.
<list>.reverse () Reverses the list <list> order.
<list>.sort ( [<function>] ) Sort the list <list>. Uses the optional compare function <function>, if given.

Tuples

Sets

Dictionaries

Files

Objects

Operators

Arithmetic operators

Operator Name Explanation
+ Plus Adds the two objects.
- Minus Either gives a negative number or gives the subtraction of one number from the other.
* Multiply Gives the multiplication of the two numbers or returns the string repeated that many times.
** Power Returns x to the power of y.
/ Divide Divide x by y.
// Floor Division Returns the floor of the quotient.
% Modulo Returns the remainder of the division.

Comparison operators

Operator Name Explanation
< Less Than Returns whether x is less than y. All comparison operators return 1 for true and 0 for false. This is equivalent to the special variables True and False respectively. Note the capitalization of these variables' names.
> Greater Than Returns whether x is greater than y.
<= Less Than or Equal To Returns whether x is less than or equal to y.
>= Greater Than or Equal To Returns whether x is greater than or equal to y.
== Equal To Compares if the objects are equal.
!= Not Equal To Compares if the objects are not equal.

Assignment Operators

Operator Name Explanation
= Assignment Assigns values from right side operands to left side operand.
+= Addition and assignment Adds right operand to the left operand and assigns the result to left operand.
-= Subtraction and assignment Subtracts right operand from the left operand and assigns the result to left operand.
*= Multiplication and assignment Multiplies right operand with the left operand and assigns the result to left operand.
/= Division and assignment Divides left operand with the right operand and assigns the result to left operand.
%= Modulo and assignment Takes modulus using two operands and assigns the result to left operand.
**= Power of and assignment Performs exponential (power) calculation on operators and assigns value to the left operand.
//= Floor division and assignment Performs floor division on operators and assigns value to the left operand.

Logical Operators

Operator Name Explanation
not Boolean NOT If x is True, it returns False. If x is False, it returns True.
and Boolean AND x and y returns False if x is False, else it returns evaluation of y.
or Boolean OR If x is True, it returns True, else it returns evaluation of y.

Bitwise Operations on Integer Types

Operator Name Explanation
<< Left Shift Shifts the bits of the number to the left by the number of bits specified.
>> Right Shift Shifts the bits of the number to the right by the number of bits specified.
& Bitwise AND Bitwise AND of the numbers.
| Bitwise OR Bitwise OR of the numbers.
^ Bitwise XOR Bitwise XOR of the numbers.
~ Bitwise Invert The bitwise inversion of x.

Membership Operators

Identity Operators

Comments

Indentation