From ab0dbb368948becb5beda50a585f9620bc186662 Mon Sep 17 00:00:00 2001 From: Christian Kolset Date: Wed, 12 Mar 2025 20:47:04 -0600 Subject: Completed Functions anr Arrays tutorial --- tutorials/1_05_basics_of_python.md | 57 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'tutorials/1_05_basics_of_python.md') diff --git a/tutorials/1_05_basics_of_python.md b/tutorials/1_05_basics_of_python.md index 59a9c63..5cc9aee 100644 --- a/tutorials/1_05_basics_of_python.md +++ b/tutorials/1_05_basics_of_python.md @@ -2,13 +2,23 @@ This page contains important fundamental concepts used in Python such as syntax, operators, order or precedence and more. +[Syntax](1_05_basics_of_python#Syntax) +[Operators](1_05_basics_of_python#Operators) +[Order of operation](1_05_basics_of_python#Order%20of%20Operation) +[Data types](1_05_basics_of_python#data%20types) +[Variables](1_05_basics_of_python#Variables) + +--- ## Syntax ### Indentations and blocks In python *indentations* or the space at the start of each line, signifies a block of code. This becomes important when we start working with function and loops. We will talk more about this in the controls structures tutorial. ### Comments Comments can be added to your code using the hash operator (#). Any text behind the comment operator till the end of the line will be rendered as a comment. -If you have an entire block of text or code that needs to be commented out, the triple quotation marks (""") can be used. Once used all the code after it will be considered a comment until the comment is ended with the triple quotation marks. +If you have an entire block of text or code that needs to be commented out, the triple quotation marks (""") can be used. Once used all the code after it will be considered a comment until the comment is ended with the triple quotation marks.f + +--- ## Operators +In python, operators are special symbols or keywords that perform operations on values or variables. This section covers some of the most common operator that you will see in this course. ### Arithmetic operators | Operator | Name | | --- | --- | @@ -22,6 +32,8 @@ If you have an entire block of text or code that needs to be commented out, the ### Comparison operators +Used in conditional statements such as `if` statements or `while` loops. Note that in the computer world a double equal sign (`==`) means *is equal to*, where as the single equal sign assigns the variable or defines the variable to be something. + | Operator | Name | | --- | --- | | == | Equal | @@ -44,27 +56,33 @@ If you have an entire block of text or code that needs to be commented out, the | is | Returns True if both variables are the same object | | is not | Returns True if both variables are not the same object | +--- ## Order of Operation -| Operator | Description | -| --- | --- | -| () | Parentheses | -| ** | Exponentiation | -| * / // % | Multiplication, Division, floor division, and modulus | -| & | AND | -| ^ | XOR | -| \| | OR | -| == | Comparision, identity and membership operators | -| not | logical NOT | -| and | AND | -| or | OR | - - +Similarly to the order or precedence in mathematics, different computer languages have their own set of rules. Here is a comprehensive table of the order of operation that python follows. + +| Operator | Description | +| ------------------------------------------------------- | ----------------------------------------------------- | +| `()` | Parentheses | +| `**` | Exponentiation | +| `+x` `-x` `~x` | Unary plus, unary minus, and bitwise NOT | +| `*` `/` `//` `%` | Multiplication, Division, floor division, and modulus | +| `+` `-` | Addition and subtraction | +| `<<` `>>` | Bitwise left and right shifts | +| & | Bitwise AND | +| ^ | Bitwise XOR | +| \| | Bitwise OR | +| `==` `!=` `>` `>=` `<` `<=` `is` `is not` `in` `not in` | Comparision, identity and membership operators | +| `not` | logical NOT | +| `and` | AND | +| `or` | OR | + +--- ## Data types Data types are different ways a computer stores data. Other data types use fewer bits than others allowing you to better utilize your computer memory. This is important for engineers because The most common data types that an engineer encounters in python are numeric types. -- 'int' - integer -- 'float' - a decimal number -- 'complex' - imaginary number +- `int` - integer +- `float` - a decimal number +- `complex` - imaginary number The comprehensive table below show all built-in data types available in python. @@ -78,13 +96,14 @@ The comprehensive table below show all built-in data types available in python. | Binary | bytes, bytearray, memoryview | | None | NoneType | +--- ## Variables A **variable** in Python is a name that stores a value, allowing you to use and manipulate data efficiently. #### Declaring and Assigning Variables -In Python, you don’t need to declare the type of a variable. Just assign a value using `=`. +It is common in low-level computer languages to declare the datatype if the variable. In python, the datatype is set whilst you assign it. We assign values to variables using a single `=`. ```python x = 10 # Integer -- cgit v1.2.3