summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kolset <christian.kolset@gmail.com>2025-02-11 18:02:50 -0700
committerChristian Kolset <christian.kolset@gmail.com>2025-02-11 18:02:50 -0700
commitc4e55bd19805d6a1ea9fbda8975a87e8d9747efa (patch)
tree544b24cbc5a2fcb8d8bc578a337ee1d14a0bca08
parentd15b47d5a0a58515b64e2f57d4b6ab2b86e404be (diff)
Added Variables section
-rw-r--r--tutorials/basics_of_python.md82
1 files changed, 77 insertions, 5 deletions
diff --git a/tutorials/basics_of_python.md b/tutorials/basics_of_python.md
index abced24..5c12ff4 100644
--- a/tutorials/basics_of_python.md
+++ b/tutorials/basics_of_python.md
@@ -1,12 +1,13 @@
# Basics of Python
-^88ce39
-
This page contains important fundamental concepts used in Python such as syntax, operators, order or precedence and more.
## Syntax
+### Indentations
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.
-
+### 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.
## Operators
### Arithmetic operators
| Operator | Name |
@@ -57,8 +58,6 @@ In python *indentations* or the space at the start of each line, signifies a blo
| and | AND |
| or | OR |
-## 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.
## 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
@@ -81,3 +80,76 @@ The comprehensive table below show all built-in data types available in python.
| Boolean | bytes, bytearray, memoryview |
| 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.
+
+#### 1. Declaring and Assigning Variables
+
+In Python, you don’t need to declare the type of a variable. Just assign a value using `=`.
+
+```python
+x = 10 # Integer
+y = 3.14 # Float
+name = "Joe" # String
+is_valid = True # Boolean
+```
+
+#### Rules
+
+- Must start with a letter or `_`
+- Cannot start with a number
+- Can only contain letters, numbers, and `_`
+- Case-sensitive (`Name` and `name` are different)
+
+#### **4. Updating Variables**
+
+You can change a variable’s value at any time.
+
+```python
+x = 5
+x = x + 10 # Now x is 15
+```
+
+Or shorthand:
+
+```python
+x += 10 # Same as x = x + 10
+```
+
+#### **5. Multiple Assignments**
+
+You can assign multiple variables at once:
+
+```python
+a, b, c = 1, 2, 3
+```
+
+Similarly we can assign the same value to multiple variables:
+
+```python
+x = y = z = 100
+```
+
+#### **6. Variable Types & Type Checking**
+
+Use `type()` to check a variable’s type.
+
+```python
+x = 10
+print(type(x)) # Output: <class 'int'>
+
+y = "Hello"
+print(type(y)) # Output: <class 'str'>
+```
+
+
+#### 8. Deleting Variables
+
+Use `del` to remove a variable:
+
+```python
+x = 10
+del x
+```