diff --git a/Udemy/Python Masterclass/11.casting.md b/Udemy/Python Masterclass/11.casting.md new file mode 100644 index 00000000..420bbe3b --- /dev/null +++ b/Udemy/Python Masterclass/11.casting.md @@ -0,0 +1,127 @@ +# Casting (Changing the data type) + +## Strings & Integer Variables + +```python +number1 = "5" # string variable +number2 = 10 # integer variable +``` + +Right now, we've got two (2) variables set: + +* Number1 (String) | Value = "5" + +* Number2 (Integer) | Value = 10 + +### Error 1 + +If I just added these 2 variables together: + +```py +number3 = number1 + number2 # results in a syntax error +``` + +#### Fixing error 1 + +```python +number3 = int(number1) + number2 +``` + +By adding "int(" to the variable, we change the data type of variable "number1" from a **string** into an **integer.** + +```python +print(number3) # prints "15" +``` + +### Adding 2 strings together + +```python +number3 = number1 + str(number2) # prints "510" as 10 is added to the right of the 5, like how you would add two characters/letters together, as both variables are now strings +``` + +### Error 2 + +```python +number1 = "ggg" +number2 = 5 +number3 = number2 + number1 +``` + +Even if I was to convert "number1" into a string, there would still be an error: + +```python +number3 = int(number1) + number2 +``` + +And this is because "ggg" is not a number, so it is an invalid value for any integer or float variable. + +However, we can add these two variables together: + +##### Fixing Error 2 + +```python +number3 = number1 + str(number2) # and this gives us "ggg5" // See "adding two strings together" +``` + +### Floats + +```python +number1 = 11.55 +number2 = 3 # could be represented as a float or an integer, but to make sure it's an integer: + +number2 = int(number2) + +number3 = number1 + number2 +``` + +```python +number3 = float(number2) + number1 +``` + +The same rules regarding converting strings/integers also apply to floats + +#### Types of errors + +* Syntax + +* Type + +### Other stuff + +* Changing a variable's data type to the current data type does not result in an error and the program continues to run + +## Full code + +```py +number1 = "5" # string variable +number2 = 10 # integer variable + +# number3 = number1 + number2 // Error 1 + +number3 = int(number1) + number2 # Fixing Error 1 +print(number3) + + +number1 = "ggg" +number2 = 5 + +#number3 = number1 + number2 + + +number3 = number1 + str(number2) +print(number3) + + +number1 = 11.55 +number2 = 3 # could be represented as a float or an integer, but to make sure it's an integer: + +number2 = int(number2) + +number3 = number1 + number2 +``` + +## File Information + +* File Link: https://github.com/irisdroidology/python-learning/master/udemy/python-masterclass/11.casting.md + +* Discussion link: http://acord.software/stellarios/python-discussion diff --git a/Udemy/Python Masterclass/12.strings.md b/Udemy/Python Masterclass/12.strings.md new file mode 100644 index 00000000..77ebd03e --- /dev/null +++ b/Udemy/Python Masterclass/12.strings.md @@ -0,0 +1,42 @@ +# Strings + +These are both strings: + +```python +"string" +'string' +``` + + + +```python +stringVar = "Hello" # string variable aka +``` + +## Printing parts of a string + +```python +print(stringVar) # prints whole string +print(stringVar[0]) # index value - starting from 0 // Prints "H" +print(stringVar[1]) ## prints "e" +``` + +* Indexing is how we can print parts of a string (as well as doing other things) + +* Index values start from 0 - the first value of a variable is the "0th" or where the index value is 0 + + + +An error: + +```python +print(stringVar[5]) # index error +``` + +* While there are 5 characters in the string "stringVar", if the index value is 5, then it is referring to the **6th** character, which doesn't exist, thus resulting in an index error: + +* ``` + string index out of range + ``` + +* diff --git a/Udemy/Python Masterclass/14-calculator-app.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/14-calculator-app.py similarity index 100% rename from Udemy/Python Masterclass/14-calculator-app.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/14-calculator-app.py diff --git a/Udemy/Python Masterclass/15.advanced-operators.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/15.advanced-operators.py similarity index 100% rename from Udemy/Python Masterclass/15.advanced-operators.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/15.advanced-operators.py diff --git a/Udemy/Python Masterclass/16-Logical-Operators.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/16-Logical-Operators.py similarity index 100% rename from Udemy/Python Masterclass/16-Logical-Operators.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/16-Logical-Operators.py diff --git a/Udemy/Python Masterclass/17-conditionals.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/17-conditionals.py similarity index 100% rename from Udemy/Python Masterclass/17-conditionals.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/17-conditionals.py diff --git a/Udemy/Python Masterclass/20-application-conditions.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/20-application-conditions.py similarity index 100% rename from Udemy/Python Masterclass/20-application-conditions.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/20-application-conditions.py diff --git a/Udemy/Python Masterclass/21-lists.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/21-lists.py similarity index 100% rename from Udemy/Python Masterclass/21-lists.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/21-lists.py diff --git a/Udemy/Python Masterclass/22-tuples.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/22-tuples.py similarity index 100% rename from Udemy/Python Masterclass/22-tuples.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/22-tuples.py diff --git a/Udemy/Python Masterclass/23-sets.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/23-sets.py similarity index 100% rename from Udemy/Python Masterclass/23-sets.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/23-sets.py diff --git a/Udemy/Python Masterclass/24-list-operators.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/24-list-operators.py similarity index 100% rename from Udemy/Python Masterclass/24-list-operators.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/24-list-operators.py diff --git a/Udemy/Python Masterclass/25-tuple-operators.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/25-tuple-operators.py similarity index 100% rename from Udemy/Python Masterclass/25-tuple-operators.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/25-tuple-operators.py diff --git a/Udemy/Python Masterclass/26-Set-Operators.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/26-Set-Operators.py similarity index 100% rename from Udemy/Python Masterclass/26-Set-Operators.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/26-Set-Operators.py diff --git a/Udemy/Python Masterclass/26-for-loops.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/26-for-loops.py similarity index 100% rename from Udemy/Python Masterclass/26-for-loops.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/26-for-loops.py diff --git a/Udemy/Python Masterclass/28-Range Function.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/28-Range Function.md similarity index 100% rename from Udemy/Python Masterclass/28-Range Function.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/28-Range Function.md diff --git a/Udemy/Python Masterclass/30-break,continue.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/30-break,continue.md similarity index 100% rename from Udemy/Python Masterclass/30-break,continue.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/30-break,continue.md diff --git a/Udemy/Python Masterclass/31-dictionary.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/31-dictionary.md similarity index 100% rename from Udemy/Python Masterclass/31-dictionary.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/31-dictionary.md diff --git a/Udemy/Python Masterclass/32-files-in-python.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/32-files-in-python.md similarity index 100% rename from Udemy/Python Masterclass/32-files-in-python.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/32-files-in-python.md diff --git a/Udemy/Python Masterclass/37-functions-in-python-1.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/37-functions-in-python-1.md similarity index 100% rename from Udemy/Python Masterclass/37-functions-in-python-1.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/37-functions-in-python-1.md diff --git a/Udemy/Python Masterclass/Casting.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/Casting.py similarity index 100% rename from Udemy/Python Masterclass/Casting.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/Casting.py diff --git a/Udemy/Python Masterclass/README.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/README.md similarity index 100% rename from Udemy/Python Masterclass/README.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/README.md diff --git a/Udemy/Python Masterclass/closer-look-numbers.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/closer-look-numbers.py similarity index 100% rename from Udemy/Python Masterclass/closer-look-numbers.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/closer-look-numbers.py diff --git a/Udemy/Python Masterclass/getting-input.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/getting-input.py similarity index 100% rename from Udemy/Python Masterclass/getting-input.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/getting-input.py diff --git a/Udemy/Python Masterclass/introduction-masterclass.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/introduction-masterclass.py similarity index 100% rename from Udemy/Python Masterclass/introduction-masterclass.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/introduction-masterclass.py diff --git a/Udemy/Python Masterclass/numpy-arrays-intro.md b/Udemy/Python Masterclass/Initial Run (Issue #17)/numpy-arrays-intro.md similarity index 100% rename from Udemy/Python Masterclass/numpy-arrays-intro.md rename to Udemy/Python Masterclass/Initial Run (Issue #17)/numpy-arrays-intro.md diff --git a/Udemy/Python Masterclass/starting-operations.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/starting-operations.py similarity index 100% rename from Udemy/Python Masterclass/starting-operations.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/starting-operations.py diff --git a/Udemy/Python Masterclass/strings.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/strings.py similarity index 100% rename from Udemy/Python Masterclass/strings.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/strings.py diff --git a/Udemy/Python Masterclass/stuff-to-remember.py b/Udemy/Python Masterclass/Initial Run (Issue #17)/stuff-to-remember.py similarity index 100% rename from Udemy/Python Masterclass/stuff-to-remember.py rename to Udemy/Python Masterclass/Initial Run (Issue #17)/stuff-to-remember.py