├── .gitignore ├── 02_FileHandling ├── demofile.txt └── 01_FileHandling.py ├── 01_PythonTutorial ├── 001_Home.py ├── 003_SintaxTwo.py ├── 057_EvaluateVariables2.py ├── 061_FunctionsCanReturnBooleans.py ├── 063_DemoBoolean3.py ├── 062_DemoBoolean2.py ├── 006_GetTheType.py ├── 024_Complex.py ├── 008_CaseSensitive.py ├── 033_StingLength.py ├── 007_SingleOrDoubleQuotes.py ├── 012_OneValueMultiplesVariables.py ├── 051_TableEscapeCharacters.txt ├── 056_EvaluateValuesAndVariables.py ├── 011_ManyValuesMultipleVariables.py ├── 022_Init.py ├── 002_Sintax.py ├── 029_AssignStringVariable.py ├── 040_UpperCase.py ├── 041_LowerCase.py ├── 021_Numbers.py ├── 017_TheGlobalKeyword.py ├── 043_ReplaceString.py ├── 005_Variables.py ├── 015_OutputVariablesTwo.py ├── 055_TrueOrFalse.py ├── 016_GlobalVariables.py ├── 042_RemoveWhitespace.py ├── 013_UnpackCollection.py ├── 014_OutpuyVariables.py ├── 038_SliceEnd.py ├── 060_SomeValuesAreFalse2.py ├── 028_Strings.py ├── 037_SliceFromStart.py ├── 035_CheckIfNot.py ├── 004_Comments.py ├── 058_MostValuesAreTrue.py ├── 023_Float.py ├── 025_TypeConversion.py ├── 039_NegativeIndexing.py ├── 032_LoopingThroughString.py ├── 053_TestExercises.py ├── 059_SomeValuesAreFalse.py ├── 054_PythonBooleans.py ├── 036_Slicing.py ├── 046_StringConcatenation.py ├── 044_SplitString.py ├── 018_DataType.py ├── 010_MultiWordsVariableNames.py ├── 031_StringsArrays.py ├── 034_CheckString.py ├── 020_SettingSpecificDataType.py ├── 009_VariableNames.py ├── 047_StringFormat.py ├── 030_MultilineStrings.py ├── 019_SettingDataType.py ├── 049_EscapeCharacters.py ├── 048_StringFormat2.py ├── 050_EscapeCharacters2.py ├── 027_SpecifiVariableType.py ├── 026_RandomNumber.py ├── 045_StringMethods.py └── 052_StringMethods.py ├── 12_PythonExamples ├── 001_PrintHelloWorld.py ├── 002_Comments.py └── 003_Docstring.py ├── 10_ModuleReference └── 01_Intro.py ├── 11_PythonHowTo └── 01_RemoveDuplicatesList.py ├── 04_PythonMatplotlib └── 001_Intro.py ├── 07_PythonMySQL └── 001_Introduction.py ├── 08_PythonMongoDB └── 001_Introduction.py ├── LICENSE ├── 05_PythonSciPy └── 001_Intro.py ├── 09_PythonReference └── 001_Overview.py ├── 03_PythonNumpy └── 001_Introduction.py ├── 06_MachineLearning └── 001_GettingStarted.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode -------------------------------------------------------------------------------- /02_FileHandling/demofile.txt: -------------------------------------------------------------------------------- 1 | DemoFile Owo -------------------------------------------------------------------------------- /01_PythonTutorial/001_Home.py: -------------------------------------------------------------------------------- 1 | print("Hello, World!") -------------------------------------------------------------------------------- /12_PythonExamples/001_PrintHelloWorld.py: -------------------------------------------------------------------------------- 1 | print("Hello, World!") 2 | -------------------------------------------------------------------------------- /12_PythonExamples/002_Comments.py: -------------------------------------------------------------------------------- 1 | #This is a comment. 2 | print("Hello, comment!") 3 | -------------------------------------------------------------------------------- /01_PythonTutorial/003_SintaxTwo.py: -------------------------------------------------------------------------------- 1 | #Python Variables 2 | 3 | x = 5 4 | y = "Hello, World!" 5 | z = 4 6 | 7 | print(z+x) -------------------------------------------------------------------------------- /12_PythonExamples/003_Docstring.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This is a 3 | multiline docstring. 4 | ''' 5 | 6 | print("Hello,Docstring!") -------------------------------------------------------------------------------- /01_PythonTutorial/057_EvaluateVariables2.py: -------------------------------------------------------------------------------- 1 | #Evaluate two variables: 2 | 3 | x = "Hello" 4 | y = 15 5 | 6 | print(bool(x)) 7 | print(bool(y)) -------------------------------------------------------------------------------- /01_PythonTutorial/061_FunctionsCanReturnBooleans.py: -------------------------------------------------------------------------------- 1 | #Functions can Return a Boolean 2 | def myFunction() : 3 | return True 4 | 5 | print(myFunction()) -------------------------------------------------------------------------------- /01_PythonTutorial/063_DemoBoolean3.py: -------------------------------------------------------------------------------- 1 | x = 200 2 | print(isinstance(x, int)) 3 | 4 | # isinstanc: https://www.w3schools.com/python/ref_func_isinstance.asp -------------------------------------------------------------------------------- /01_PythonTutorial/062_DemoBoolean2.py: -------------------------------------------------------------------------------- 1 | def myFunction() : 2 | return False 3 | 4 | if myFunction(): 5 | print("YES!") 6 | else: 7 | print("NO!") 8 | -------------------------------------------------------------------------------- /01_PythonTutorial/006_GetTheType.py: -------------------------------------------------------------------------------- 1 | #You can get the data type of a variable with the type() function. 2 | 3 | x = 5 4 | y = "John" 5 | print(type(x)) 6 | print(type(y)) -------------------------------------------------------------------------------- /01_PythonTutorial/024_Complex.py: -------------------------------------------------------------------------------- 1 | #Complex numbers are written with a "j" as the imaginary part: 2 | 3 | x = 3+5j 4 | y = 5j 5 | z = -5j 6 | 7 | print(type(x)) 8 | print(type(y)) 9 | print(type(z)) -------------------------------------------------------------------------------- /01_PythonTutorial/008_CaseSensitive.py: -------------------------------------------------------------------------------- 1 | #Case-Sensitive: Variable names are case-sensitive. 2 | 3 | #This will create two variables: 4 | a = "4" 5 | A = "Sally" 6 | #A will not overwrite a 7 | print(a +" "+ A) -------------------------------------------------------------------------------- /01_PythonTutorial/033_StingLength.py: -------------------------------------------------------------------------------- 1 | #String Length 2 | 3 | a = "Good Morning owO!" 4 | print(len(a)) 5 | 6 | ''' 7 | Terminal: 8 | 17 9 | ''' 10 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/007_SingleOrDoubleQuotes.py: -------------------------------------------------------------------------------- 1 | #Single or Double Quotes? 2 | #String variables can be declared either by using single or double quotes: 3 | 4 | x = "John" 5 | # is the same as 6 | x = 'John' 7 | 8 | print(x) -------------------------------------------------------------------------------- /01_PythonTutorial/012_OneValueMultiplesVariables.py: -------------------------------------------------------------------------------- 1 | '''Many Values to Multiple Variables 2 | Python allows you to assign values to multiple variables in one line:''' 3 | 4 | x = y = z = "Orange" 5 | print(x) 6 | print(y) 7 | print(z) -------------------------------------------------------------------------------- /01_PythonTutorial/051_TableEscapeCharacters.txt: -------------------------------------------------------------------------------- 1 | 2 | \' Single Quote 3 | \\ Backslash 4 | \n New Line 5 | \r Carriage Return 6 | \t Tab 7 | \b Backspace 8 | \f Form Feed 9 | \ooo Octal value 10 | \xhh Hex value 11 | -------------------------------------------------------------------------------- /01_PythonTutorial/056_EvaluateValuesAndVariables.py: -------------------------------------------------------------------------------- 1 | #Evaluate Values and Variables 2 | '''The bool() function allows you to evaluate any value, and give you True or False in return,''' 3 | 4 | print(bool("Hello")) 5 | print(bool(15)) -------------------------------------------------------------------------------- /01_PythonTutorial/011_ManyValuesMultipleVariables.py: -------------------------------------------------------------------------------- 1 | '''Many Values to Multiple Variables 2 | Python allows you to assign values to multiple variables in one line:''' 3 | 4 | x, y, z = "Orange", "Banana", "Cherry" 5 | print(x) 6 | print(y) 7 | print(z) 8 | -------------------------------------------------------------------------------- /01_PythonTutorial/022_Init.py: -------------------------------------------------------------------------------- 1 | x = 1 2 | y = 35656222554887711 3 | z = -3255522 4 | 5 | print(type(x)) 6 | print(type(y)) 7 | print(type(z)) 8 | 9 | ''' Int = Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. ''' -------------------------------------------------------------------------------- /01_PythonTutorial/002_Sintax.py: -------------------------------------------------------------------------------- 1 | #Al menos debes usar un escpacio o no va a compilar 2 | 3 | #Buen Espacio 4 | if 5 > 2: 5 | print("Five is greater than two!") 6 | 7 | #Mucho espacio 8 | 9 | if 10 > 9: 10 | print("10 is greater than nine!") 11 | 12 | -------------------------------------------------------------------------------- /01_PythonTutorial/029_AssignStringVariable.py: -------------------------------------------------------------------------------- 1 | #Assign String to a Variable 2 | '''Assigning a string to a variable is done with the variable name followed by an equal sign and the string:''' 3 | 4 | a = "Hello" 5 | print(a) 6 | 7 | ''' 8 | Terminal: 9 | Hello 10 | ''' -------------------------------------------------------------------------------- /01_PythonTutorial/040_UpperCase.py: -------------------------------------------------------------------------------- 1 | #Upper Case 2 | 3 | #The upper() method returns the string in upper case: 4 | a = "Hello, World!" 5 | print(a.upper()) 6 | 7 | ''' 8 | Terminal: 9 | HELLO, WORLD! 10 | ''' 11 | #https://www.w3schools.com/python/python_strings_modify.asp -------------------------------------------------------------------------------- /01_PythonTutorial/041_LowerCase.py: -------------------------------------------------------------------------------- 1 | #Lowe Case 2 | 3 | #The lower() method returns the string in lower case: 4 | a = "Hello, World!" 5 | print(a.lower()) 6 | 7 | ''' 8 | Terminal: 9 | hello, world! 10 | ''' 11 | #https://www.w3schools.com/python/python_strings_modify.asp -------------------------------------------------------------------------------- /01_PythonTutorial/021_Numbers.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Python Numbers 3 | There are three numeric types in Python: 4 | 5 | int 6 | float 7 | complex 8 | ''' 9 | 10 | x = 1 # int 11 | y = 2.8 # float 12 | z = 1j # complex 13 | 14 | print(type(x)) 15 | print(type(y)) 16 | print(type(z)) -------------------------------------------------------------------------------- /01_PythonTutorial/017_TheGlobalKeyword.py: -------------------------------------------------------------------------------- 1 | def myfunc(): 2 | global x #esto es lo que hace que la variable sea global y no solo sirva en la funcion 3 | x = "fantastic" 4 | print("Esto se imprime por una funcion!") 5 | 6 | myfunc() 7 | 8 | print("Python is " + x) 9 | 10 | 11 | -------------------------------------------------------------------------------- /01_PythonTutorial/043_ReplaceString.py: -------------------------------------------------------------------------------- 1 | #Replace String 2 | 3 | #The replace() method replaces a string with another string: 4 | a = "Hello, World!" 5 | print(a.replace("H", "J")) 6 | 7 | ''' 8 | Terminal: 9 | Jello, World! 10 | ''' 11 | #https://www.w3schools.com/python/python_strings_modify.asp -------------------------------------------------------------------------------- /01_PythonTutorial/005_Variables.py: -------------------------------------------------------------------------------- 1 | #Python has no command for declaring a variable. 2 | #A variable is created the moment you first assign a value to it. 3 | 4 | x = 5 5 | y = "John" 6 | print(x) 7 | print(y) 8 | 9 | a = 4 # x is of type int 10 | a = "Sally" # x is now of type str 11 | print(a) -------------------------------------------------------------------------------- /01_PythonTutorial/015_OutputVariablesTwo.py: -------------------------------------------------------------------------------- 1 | #For numbers, the + character works as a mathematical operator: 2 | x = 598789 3 | y = 106565 4 | print(x + y) 5 | 6 | 7 | ''' 8 | x = 5 9 | y = "John" 10 | print(x + y) 11 | 12 | Esto daria error ya que las variables son de diferentes tipos 13 | ''' 14 | -------------------------------------------------------------------------------- /01_PythonTutorial/055_TrueOrFalse.py: -------------------------------------------------------------------------------- 1 | '''When you run a condition in an if statement, Python returns True or False:''' 2 | 3 | #Print a message based on whether the condition is True or False: 4 | a = 200 5 | b = 33 6 | 7 | if b > a: 8 | print("b is greater than a") 9 | else: 10 | print("b is not greater than a") -------------------------------------------------------------------------------- /01_PythonTutorial/016_GlobalVariables.py: -------------------------------------------------------------------------------- 1 | #x = "awesome" 2 | 3 | def myfunc(): 4 | print("Python is " + x) 5 | 6 | #myfunc() 7 | '''''''''''''''''''''''''''''''''''' 8 | x = "awesome" 9 | 10 | def myfunc2(): 11 | x = "fantastic" 12 | print("Python is " + x) 13 | 14 | myfunc2() 15 | 16 | print("Python is " + x) -------------------------------------------------------------------------------- /01_PythonTutorial/042_RemoveWhitespace.py: -------------------------------------------------------------------------------- 1 | #Remove Whitespace 2 | 3 | #The strip() method removes any whitespace from the beginning or the end: 4 | a = " Hello, World! " 5 | print(a.strip()) # returns "Hello, World!" 6 | 7 | ''' 8 | Terminal: 9 | Hello, World! 10 | ''' 11 | #https://www.w3schools.com/python/python_strings_modify.asp -------------------------------------------------------------------------------- /01_PythonTutorial/013_UnpackCollection.py: -------------------------------------------------------------------------------- 1 | '''Unpack a Collection 2 | If you have a collection of values in a list, tuple etc. Python allows you extract the values into variables. This is called unpacking.''' 3 | 4 | #Unpack a list: 5 | 6 | fruits = ["Apple", "Banana", "Cherry"] 7 | x, y, z = fruits 8 | print(x) 9 | print(y) 10 | print(z) -------------------------------------------------------------------------------- /01_PythonTutorial/014_OutpuyVariables.py: -------------------------------------------------------------------------------- 1 | '''Output Variables 2 | The Python print statement is often used to output variables. 3 | 4 | To combine both text and a variable, Python uses the + character:''' 5 | 6 | x = "awesome" 7 | print("Python is " + x) 8 | 9 | #equal to : 10 | 11 | x = "Python is " 12 | y = "awesome" 13 | z = x + y 14 | print(z) -------------------------------------------------------------------------------- /01_PythonTutorial/038_SliceEnd.py: -------------------------------------------------------------------------------- 1 | #Slice To the End 2 | '''By leaving out the end index, the range will go to the end:''' 3 | 4 | #Get the characters from position 2, and all the way to the end: 5 | b = "Heyo, World!" 6 | print(b[2:]) 7 | 8 | ''' 9 | Terminal: 10 | yo, World! 11 | ''' 12 | #https://www.w3schools.com/python/python_strings_slicing.asp -------------------------------------------------------------------------------- /01_PythonTutorial/060_SomeValuesAreFalse2.py: -------------------------------------------------------------------------------- 1 | #Some Values are False 2 | '''One more value, or object in this case, evaluates to False, 3 | and that is if you have an object that is made from a class with a __len__ function that returns 0 or False:''' 4 | 5 | class myclass(): 6 | def __len__(self): 7 | return 0 8 | 9 | myobj = myclass() 10 | print(bool(myobj)) -------------------------------------------------------------------------------- /10_ModuleReference/01_Intro.py: -------------------------------------------------------------------------------- 1 | #Module Reference 2 | 3 | ''' 4 | Random Module https://www.w3schools.com/python/module_random.asp 5 | 6 | Request Module https://www.w3schools.com/python/module_requests.asp 7 | 8 | Math Module https://www.w3schools.com/python/module_requests.asp 9 | 10 | CMath Module https://www.w3schools.com/python/module_cmath.asp 11 | ''' 12 | -------------------------------------------------------------------------------- /01_PythonTutorial/028_Strings.py: -------------------------------------------------------------------------------- 1 | #Strings 2 | '''Strings in python are surrounded by either single quotation marks, or double quotation marks. 3 | 4 | 'hello' is the same as "hello".''' 5 | 6 | #You can display a string literal with the print() function: 7 | 8 | print("Hello") #its equal to 9 | print('Hello') 10 | 11 | 12 | ''' 13 | Terminal: 14 | Hello 15 | Hello 16 | ''' -------------------------------------------------------------------------------- /01_PythonTutorial/037_SliceFromStart.py: -------------------------------------------------------------------------------- 1 | #Slice From the Start 2 | '''By leaving out the start index, the range will start at the first character:''' 3 | 4 | #Get the characters from the start to position 5 (not included): 5 | b = "Hello, World!" 6 | print(b[:5]) 7 | 8 | ''' 9 | Terminal: 10 | Hello 11 | ''' 12 | #https://www.w3schools.com/python/python_strings_slicing.asp -------------------------------------------------------------------------------- /01_PythonTutorial/035_CheckIfNot.py: -------------------------------------------------------------------------------- 1 | #Check if NOT 2 | 3 | txt = "Hello buddie unu!" 4 | print("owo" not in txt) 5 | 6 | txt = "The best things in life are free!" 7 | if "expensive" not in txt: 8 | print("Yes, 'expensive' is NOT present.") 9 | 10 | ''' 11 | Terminal: 12 | True 13 | Yes, 'expensive' is NOT present. 14 | ''' 15 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/004_Comments.py: -------------------------------------------------------------------------------- 1 | #This is a comment. 2 | print("Hello, World!") 3 | 4 | ''' This is also a Comment ''' 5 | 6 | print("Lo que se ponga despues del # es un comentario") #This is a comment 7 | 8 | #This is a comment 9 | #written in 10 | #more than just one line 11 | print("Comentario usando #!") 12 | 13 | """ 14 | This is a comment 15 | written in 16 | more than just one line 17 | """ 18 | print("Comentarios usando ''' ") -------------------------------------------------------------------------------- /01_PythonTutorial/058_MostValuesAreTrue.py: -------------------------------------------------------------------------------- 1 | #Most Values are True 2 | ''' 3 | Almost any value is evaluated to True if it has some sort of content. 4 | 5 | Any string is True, except empty strings. 6 | 7 | Any number is True, except 0. 8 | 9 | Any list, tuple, set, and dictionary are True, except empty ones. 10 | ''' 11 | 12 | #The following will return True: 13 | 14 | bool("abc") 15 | bool(123) 16 | bool(["apple", "cherry", "banana"]) -------------------------------------------------------------------------------- /01_PythonTutorial/023_Float.py: -------------------------------------------------------------------------------- 1 | '''Float, or "floating point number" is a number, positive or negative, containing one or more decimals.''' 2 | 3 | x = 1.10 4 | y = 1.0 5 | z = -35.59 6 | 7 | print(type(x)) 8 | print(type(y)) 9 | print(type(z)) 10 | 11 | #Float can also be scientific numbers with an "e" to indicate the power of 10. 12 | 13 | a = 35e3 14 | b = 12E4 15 | c = -87.7e100 16 | 17 | print(type(a)) 18 | print(type(b)) 19 | print(type(c)) -------------------------------------------------------------------------------- /01_PythonTutorial/025_TypeConversion.py: -------------------------------------------------------------------------------- 1 | x = 1 # int 2 | y = 2.8 # float 3 | z = 1j # complex 4 | 5 | #convert from int to float: 6 | a = float(x) 7 | 8 | #convert from float to int: 9 | b = int(y) 10 | 11 | #convert from int to complex: 12 | c = complex(x) 13 | 14 | print(a) 15 | print(b) 16 | print(c) 17 | 18 | print(type(a)) 19 | print(type(b)) 20 | print(type(c)) 21 | 22 | #Note: You cannot convert complex numbers into another number type. -------------------------------------------------------------------------------- /01_PythonTutorial/039_NegativeIndexing.py: -------------------------------------------------------------------------------- 1 | #Negative Indexing 2 | '''Use negative indexes to start the slice from the end of the string:''' 3 | 4 | ''' 5 | Get the characters: 6 | 7 | From: "o" in "World!" (position -5) 8 | 9 | To, but not included: "d" in "World!" (position -2): 10 | ''' 11 | 12 | b = "Hello, World!" 13 | print(b[-5:-2]) 14 | 15 | ''' 16 | Terminal: 17 | orl 18 | ''' 19 | #https://www.w3schools.com/python/python_strings_slicing.asp -------------------------------------------------------------------------------- /01_PythonTutorial/032_LoopingThroughString.py: -------------------------------------------------------------------------------- 1 | #Looping Through a String: Since strings are arrays, we can loop through the characters in a string, with a for loop. 2 | 3 | for x in "banana": 4 | print(x) 5 | 6 | #Learn more about For Loops in our Python For Loops chapter: https://www.w3schools.com/python/python_for_loops.asp 7 | ''' 8 | Terminal: 9 | b 10 | a 11 | n 12 | a 13 | n 14 | a 15 | 16 | ''' 17 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/053_TestExercises.py: -------------------------------------------------------------------------------- 1 | x = "Hello World" 2 | print(len(x)) 3 | 4 | txt = "Hello World" 5 | y = txt[0] 6 | 7 | txt = "Hello World" 8 | z = txt[2:5] 9 | 10 | txt = " Hello World " 11 | a = txt.strip() 12 | 13 | txt = "Hello World" 14 | b = txt.upper() 15 | 16 | txt = "Hello World" 17 | c = txt.lower() 18 | 19 | txt = "Hello World" 20 | d = txt.replace("H", "J") 21 | 22 | age = 36 23 | txt = "My name is John, and I am {}" 24 | print(txt.format(age)) -------------------------------------------------------------------------------- /01_PythonTutorial/059_SomeValuesAreFalse.py: -------------------------------------------------------------------------------- 1 | #Some Values are False 2 | '''In fact, there are not many values that evaluate to False, except empty values, 3 | such as (), [], {}, "", 4 | the number 0, and the value None. And of course the value False evaluates to False.''' 5 | 6 | #The following will return False: 7 | 8 | print(bool(False)) 9 | print(bool(None)) 10 | print(bool(0)) 11 | print(bool("")) 12 | print(bool(())) 13 | print(bool([])) 14 | print(bool({})) -------------------------------------------------------------------------------- /01_PythonTutorial/054_PythonBooleans.py: -------------------------------------------------------------------------------- 1 | #Booleans represent one of two values: True or False. 2 | 3 | ''' 4 | Boolean Values 5 | 6 | In programming you often need to know if an expression is True or False. 7 | 8 | You can evaluate any expression in Python, and get one of two answers, True or False. 9 | 10 | When you compare two values, the expression is evaluated and Python returns the Boolean answer: 11 | ''' 12 | 13 | print(10 > 9) 14 | print(10 == 9) 15 | print(10 < 9) -------------------------------------------------------------------------------- /01_PythonTutorial/036_Slicing.py: -------------------------------------------------------------------------------- 1 | #Slicing 2 | ''' 3 | You can return a range of characters by using the slice syntax. 4 | 5 | Specify the start index and the end index, separated by a colon, to return a part of the string. 6 | ''' 7 | 8 | #Get the characters from position 2 to position 5 (not included): 9 | b = "Hello, World!" 10 | print(b[2:5]) 11 | 12 | #Note: The first character has index 0. 13 | 14 | ''' 15 | Terminal: 16 | llo 17 | ''' 18 | #https://www.w3schools.com/python/python_strings_slicing.asp -------------------------------------------------------------------------------- /01_PythonTutorial/046_StringConcatenation.py: -------------------------------------------------------------------------------- 1 | #String Concatenation 2 | '''To concatenate, or combine, two strings you can use the + operator.''' 3 | 4 | #Merge variable a with variable b into variable c: 5 | a = "Hello" 6 | b = "uda" 7 | c = a + b 8 | print(c) 9 | 10 | #To add a space between them, add a " ": 11 | a = "Hello" 12 | b = "World" 13 | c = a + " " + b 14 | print(c) 15 | 16 | 17 | ''' 18 | Terminal: 19 | Hellouda 20 | Hello World 21 | ''' 22 | #https://www.w3schools.com/python/python_strings_concatenate.asp -------------------------------------------------------------------------------- /11_PythonHowTo/01_RemoveDuplicatesList.py: -------------------------------------------------------------------------------- 1 | #How to Remove Duplicates From a Python List 2 | 3 | mylist = ["a", "b", "a", "c", "c"] 4 | mylist = list(dict.fromkeys(mylist)) 5 | print(mylist) 6 | 7 | #Example Explained: 8 | ''' 9 | First we have a List that contains duplicates: 10 | 11 | mylist = ["a", "b", "a", "c", "c"] 12 | mylist = list(dict.fromkeys(mylist)) 13 | print(mylist) 14 | 15 | Create a dictionary, using the List items as keys. This will automatically remove any duplicates because dictionaries cannot have duplicate keys. 16 | ''' -------------------------------------------------------------------------------- /04_PythonMatplotlib/001_Intro.py: -------------------------------------------------------------------------------- 1 | ''' 2 | What is Matplotlib? 3 | Matplotlib is a low level graph plotting library in python that serves as a visualization utility. 4 | 5 | Matplotlib was created by John D. Hunter. 6 | 7 | Matplotlib is open source and we can use it freely. 8 | 9 | Matplotlib is mostly written in python, a few segments are written in C, Objective-C and Javascript for Platform compatibility. 10 | 11 | Where is the Matplotlib Codebase? 12 | The source code for Matplotlib is located at this github repository https://github.com/matplotlib/matplotlib 13 | ''' -------------------------------------------------------------------------------- /01_PythonTutorial/044_SplitString.py: -------------------------------------------------------------------------------- 1 | #Split String 2 | '''The split() method returns a list where the text between the specified separator becomes the list items.''' 3 | 4 | #The split() method splits the string into substrings if it finds instances of the separator: 5 | a = "Hello, World!" 6 | print(a.split(",")) # returns ['Hello', ' World!'] 7 | 8 | ''' 9 | Terminal: 10 | Jello, World! 11 | ''' 12 | #https://www.w3schools.com/python/python_strings_modify.asp 13 | 14 | #Learn more about Lists in our Python Lists chapter: https://www.w3schools.com/python/python_lists.asp -------------------------------------------------------------------------------- /01_PythonTutorial/018_DataType.py: -------------------------------------------------------------------------------- 1 | '''In programming, data type is an important concept. 2 | 3 | Variables can store data of different types, and different types can do different things. 4 | 5 | Python has the following data types built-in by default, in these categories: 6 | 7 | Text Type: str 8 | Numeric Types: int, float, complex 9 | Sequence Types: list, tuple, range 10 | Mapping Type: dict 11 | Set Types: set, frozenset 12 | Boolean Type: bool 13 | Binary Types: bytes, bytearray, memoryview''' 14 | 15 | #Getting the Data Type 16 | x = 5 17 | print(type(x)) #= -------------------------------------------------------------------------------- /01_PythonTutorial/010_MultiWordsVariableNames.py: -------------------------------------------------------------------------------- 1 | '''Multi Words Variable Names 2 | Variable names with more than one word can be difficult to read. 3 | 4 | There are several techniques you can use to make them more readable''' 5 | 6 | #Each word, except the first, starts with a capital letter: 7 | myVariableName = "Camel Case" 8 | 9 | #Each word starts with a capital letter: 10 | MyVariableName = "Pascal Case" 11 | 12 | #Each word is separated by an underscore character: 13 | my_variable_name = "Snake Case" 14 | 15 | print(my_variable_name , ',' , MyVariableName ,'and' , myVariableName) -------------------------------------------------------------------------------- /01_PythonTutorial/031_StringsArrays.py: -------------------------------------------------------------------------------- 1 | #Strings are Arrays 2 | ''' 3 | Like many other popular programming languages, strings in Python are arrays of bytes representing unicode characters. 4 | 5 | However, Python does not have a character data type, a single character is simply a string with a length of 1. 6 | 7 | Square brackets can be used to access elements of the string. 8 | ''' 9 | 10 | #Get the character at position 1 (remember that the first character has the position 0): 11 | a = "Hello, World!" 12 | print(a[1]) 13 | 14 | ''' 15 | Terminal: 16 | e 17 | ''' 18 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/034_CheckString.py: -------------------------------------------------------------------------------- 1 | #Check String 2 | '''To check if a certain phrase or character is present in a string, we can use the keyword in.''' 3 | 4 | #Check if "free" is present in the following text: 5 | 6 | txt = "The best things in life are free!" 7 | print("free" in txt) 8 | 9 | txt = "Hello buddie owo!" 10 | if "owo" in txt: 11 | print("Yes, 'owo' is present.") 12 | 13 | ''' 14 | Terminal: 15 | True 16 | Yes, 'owo' is present. 17 | ''' 18 | 19 | #Learn more about If statements in our Python If...Else chapter: https://www.w3schools.com/python/python_conditions.asp 20 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/020_SettingSpecificDataType.py: -------------------------------------------------------------------------------- 1 | a = str("Hello World") #str 2 | b = int(20) #int 3 | c = float(20.5) #float 4 | d = complex(1j) #complex 5 | e = list(("apple", "banana", "cherry")) #list 6 | f = tuple(("apple", "banana", "cherry")) #tuple 7 | g = range(6) #range 8 | h = dict(name="John", age=36) #dict 9 | i = set(("apple", "banana", "cherry")) #set 10 | j = frozenset(("apple", "banana", "cherry")) #frozenset 11 | q = bool(5) #bool 12 | l = bytes(5) #bytes 13 | m = bytearray(5) #bytearray 14 | n = memoryview(bytes(5)) #memoryview 15 | 16 | print(a) 17 | print(b) 18 | print(c) 19 | print(d) 20 | print(e) 21 | print(f) 22 | print(g) 23 | print(h) 24 | print(i) 25 | print(j) 26 | print(q) 27 | print(q) 28 | print(l) 29 | print(m) 30 | print(n) -------------------------------------------------------------------------------- /01_PythonTutorial/009_VariableNames.py: -------------------------------------------------------------------------------- 1 | '''Variable Names 2 | A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for Python variables: 3 | A variable name must start with a letter or the underscore character 4 | A variable name cannot start with a number 5 | A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) 6 | Variable names are case-sensitive (age, Age and AGE are three different variables)''' 7 | 8 | #Legal variable names: 9 | myvar = "John" 10 | my_var = "John" 11 | _my_var = "John" 12 | myVar = "John" 13 | MYVAR = "John" 14 | myvar2 = "John" 15 | 16 | print(myvar) 17 | 18 | ''' 19 | Illegal variable names: 20 | 2myvar = "John" 21 | my-var = "John" 22 | my var = "John" 23 | ''' -------------------------------------------------------------------------------- /01_PythonTutorial/047_StringFormat.py: -------------------------------------------------------------------------------- 1 | #String Format 2 | 3 | ''' 4 | As we learned in the Python Variables chapter, we cannot combine strings and numbers like this: 5 | age = 36 6 | txt = "My name is John, I am " + age 7 | print(txt) 8 | 9 | Console:can only concatenate str (not "int") to str 10 | ''' 11 | '''But we can combine strings and numbers by using the format() method! 12 | 13 | The format() method takes the passed arguments, formats them, and places them in the string where the placeholders {} are:''' 14 | #Use the format() method to insert numbers into strings: 15 | age = 36 16 | txt = "My name is John, and I am {}" 17 | print(txt.format(age)) 18 | 19 | ''' 20 | Terminal: 21 | My name is John, and I am 36 22 | ''' 23 | #https://www.w3schools.com/python/python_strings_format.asp -------------------------------------------------------------------------------- /01_PythonTutorial/030_MultilineStrings.py: -------------------------------------------------------------------------------- 1 | #Multiline Strings 2 | '''You can assign a multiline string to a variable by using three quotes:''' 3 | 4 | a = """Lorem ipsum dolor sit amet, 5 | consectetur adipiscing elit, 6 | sed do eiusmod tempor incididunt 7 | ut labore et dolore magna aliqua.""" 8 | 9 | #is equal to 10 | 11 | b ='Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium.' 12 | 13 | 14 | print(a) 15 | print(b) 16 | 17 | ''' 18 | Terminal: 19 | Lorem ipsum dolor sit amet, 20 | consectetur adipiscing elit, 21 | sed do eiusmod tempor incididunt 22 | ut labore et dolore magna aliqua. 23 | Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium. 24 | ''' 25 | 26 | #Note: in the result, the line breaks are inserted at the same position as in the code. 27 | #https://www.w3schools.com/python/python_strings.asp -------------------------------------------------------------------------------- /01_PythonTutorial/019_SettingDataType.py: -------------------------------------------------------------------------------- 1 | One = "Hello World" #str 2 | Two = 20 #int 3 | Three = 20.5 #float 4 | Four = 1j #complex 5 | Five = ["apple", "banana", "cherry"] #list 6 | Six = ("apple", "banana", "cherry") #tuple 7 | Seven = range(6) #range 8 | Eight = {"name" : "John", "age" : 36} #dict 9 | Nine = {"apple", "banana", "cherry"} #set 10 | Ten = frozenset({"apple", "banana", "cherry"}) #frozenset 11 | Eleven = True #bool 12 | Twelve = b"Hello" #bytes 13 | thirteen = bytearray(5) #bytearray 14 | Fourteen = memoryview(bytes(5)) #memoryview 15 | 16 | print(type(One)) 17 | print(type(Two)) 18 | print(type(Three)) 19 | print(type(Four)) 20 | print(type(Five)) 21 | print(type(Six)) 22 | print(type(Seven)) 23 | print(type(Eight)) 24 | print(type(Nine)) 25 | print(type(Ten)) 26 | print(type(Eleven)) 27 | print(type(Twelve)) 28 | print(type(thirteen)) 29 | print(type(Fourteen)) 30 | 31 | #Comprobando -------------------------------------------------------------------------------- /01_PythonTutorial/049_EscapeCharacters.py: -------------------------------------------------------------------------------- 1 | #Escape Character 2 | ''' 3 | To insert characters that are illegal in a string, use an escape character. 4 | 5 | An escape character is a backslash \ followed by the character you want to insert. 6 | 7 | An example of an illegal character is a double quote inside a string that is surrounded by double quotes: 8 | 9 | You will get an error if you use double quotes inside a string that is surrounded by double quotes: 10 | 11 | txt = "We are the so-called "Vikings" from the north." 12 | 13 | To fix this problem, use the escape character \": 14 | ''' 15 | 16 | #The escape character allows you to use double quotes when you normally would not be allowed: 17 | txt = "We are the so-called \"Vikings\" from the north." 18 | print(txt) 19 | 20 | ''' 21 | Terminal: 22 | We are the so-called "Vikings" from the north. 23 | ''' 24 | #https://www.w3schools.com/python/python_strings_escape.asp -------------------------------------------------------------------------------- /07_PythonMySQL/001_Introduction.py: -------------------------------------------------------------------------------- 1 | #Python MySQL 2 | 3 | ''' 4 | Python can be used in database applications. 5 | 6 | One of the most popular databases is MySQL. 7 | ''' 8 | 9 | ''' 10 | MySQL Database 11 | To be able to experiment with the code examples in this tutorial, you should have MySQL installed on your computer. 12 | 13 | You can download a free MySQL database at https://www.mysql.com/downloads/. 14 | ''' 15 | 16 | ''' 17 | Install MySQL Driver 18 | Python needs a MySQL driver to access the MySQL database. 19 | 20 | In this tutorial we will use the driver "MySQL Connector". 21 | 22 | We recommend that you use PIP to install "MySQL Connector". 23 | 24 | PIP is most likely already installed in your Python environment. 25 | 26 | Navigate your command line to the location of PIP, and type the following: 27 | 28 | python -m pip install mysql-connector-python 29 | 30 | ''' 31 | #Now you have downloaded and installed a MySQL driver! -------------------------------------------------------------------------------- /01_PythonTutorial/048_StringFormat2.py: -------------------------------------------------------------------------------- 1 | #String Format Part 2 2 | 3 | #The format() method takes unlimited number of arguments, and are placed into the respective placeholders: 4 | quantity = 3 5 | itemno = 567 6 | price = 49.95 7 | myorder = "I want {} pieces of item {} for {} dollars." 8 | print(myorder.format(quantity, itemno, price)) 9 | 10 | #You can use index numbers {0} to be sure the arguments are placed in the correct placeholders: 11 | quantity = 4 12 | itemno = 456 13 | price = 99.99 14 | myorder = "I want to pay {2} dollars for {0} pieces of item {1}." 15 | print(myorder.format(quantity, itemno, price)) 16 | 17 | ''' 18 | Terminal: 19 | I want 3 pieces of item 567 for 49.95 dollars. 20 | I want to pay 99.99 dollars for 4 pieces of item 456. 21 | ''' 22 | #Learn more about String Formatting in our String Formatting chapter: https://www.w3schools.com/python/python_string_formatting.asp 23 | #https://www.w3schools.com/python/python_strings_format.asp 24 | -------------------------------------------------------------------------------- /01_PythonTutorial/050_EscapeCharacters2.py: -------------------------------------------------------------------------------- 1 | #Escape Characters 2 | 3 | #The Table is in 051_TableEscapeCharacters.txt 4 | 5 | SingleQuote = "The humans are \'Inhumans\' sometimes." 6 | print(SingleQuote) 7 | 8 | Backslash = "This will insert one \\ (backslash)." 9 | print(Backslash) 10 | 11 | NewLine = "Hello\nWorld!" 12 | print(NewLine) 13 | 14 | CarriageReturn = "Hello\rWorld!" 15 | print(CarriageReturn) 16 | 17 | AnSpace = "So\tSpace!" 18 | print(AnSpace) 19 | 20 | #This example erases one character (backspace): 21 | EraseBackSpace = "Little \bSpace!" 22 | print(EraseBackSpace) 23 | 24 | #A backslash followed by three integers will result in a octal value: 25 | txt = "\110\145\154\154\157" 26 | print(txt) 27 | 28 | #A backslash followed by an 'x' and a hex number represents a hex value: 29 | txt = "\x48\x65\x6c\x6c\x6f" 30 | print(txt) 31 | 32 | 33 | ''' 34 | Terminal: 35 | The humans are 'Inhumans' sometimes. 36 | This will insert one \ (backslash). 37 | Hello 38 | World! 39 | World! 40 | So Space! 41 | LittleSpace! 42 | Hello 43 | Hello 44 | ''' 45 | # -------------------------------------------------------------------------------- /08_PythonMongoDB/001_Introduction.py: -------------------------------------------------------------------------------- 1 | #Python MongoDB 2 | ''' 3 | Python can be used in database applications. 4 | 5 | One of the most popular NoSQL database is MongoDB. 6 | ''' 7 | 8 | ''' 9 | MongoDB 10 | MongoDB stores data in JSON-like documents, which makes the database very flexible and scalable. 11 | 12 | To be able to experiment with the code examples in this tutorial, you will need access to a MongoDB database. 13 | 14 | You can download a free MongoDB database at https://www.mongodb.com. 15 | 16 | Or get started right away with a MongoDB cloud service at https://www.mongodb.com/cloud/atlas. 17 | ''' 18 | 19 | ''' 20 | PyMongo 21 | Python needs a MongoDB driver to access the MongoDB database. 22 | 23 | In this tutorial we will use the MongoDB driver "PyMongo". 24 | 25 | We recommend that you use PIP to install "PyMongo". 26 | 27 | PIP is most likely already installed in your Python environment. 28 | 29 | Navigate your command line to the location of PIP, and type the following: 30 | 31 | python -m pip install pymongo 32 | ''' 33 | #Now you have downloaded and installed a mongoDB driver. 34 | 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Eliaz Bobadilla 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /05_PythonSciPy/001_Intro.py: -------------------------------------------------------------------------------- 1 | #SciPy Introduction 2 | 3 | ''' 4 | What is SciPy? 5 | SciPy is a scientific computation library that uses NumPy underneath. 6 | 7 | SciPy stands for Scientific Python. 8 | 9 | It provides more utility functions for optimization, stats and signal processing. 10 | 11 | Like NumPy, SciPy is open source so we can use it freely. 12 | 13 | SciPy was created by NumPy's creator Travis Olliphant. 14 | ''' 15 | 16 | ''' 17 | 18 | What is SciPy? 19 | SciPy is a scientific computation library that uses NumPy underneath. 20 | 21 | SciPy stands for Scientific Python. 22 | 23 | It provides more utility functions for optimization, stats and signal processing. 24 | 25 | Like NumPy, SciPy is open source so we can use it freely. 26 | 27 | SciPy was created by NumPy's creator Travis Olliphant. 28 | 29 | Why Use SciPy? 30 | If SciPy uses NumPy underneath, why can we not just use NumPy? 31 | 32 | SciPy has optimized and added functions that are frequently used in NumPy and Data Science. 33 | 34 | Which Language is SciPy Written in? 35 | SciPy is predominantly written in Python, but a few segments are written in C. 36 | 37 | ''' 38 | 39 | #The source code for SciPy is located at this github repository https://github.com/scipy/scipy -------------------------------------------------------------------------------- /09_PythonReference/001_Overview.py: -------------------------------------------------------------------------------- 1 | #Python Reference 2 | 3 | ''' 4 | Built-in Functions https://www.w3schools.com/python/python_ref_functions.asp 5 | 6 | String Mehods https://www.w3schools.com/python/python_ref_string.asp 7 | 8 | List Methods https://www.w3schools.com/python/python_ref_list.asp 9 | 10 | Dictionary Methods https://www.w3schools.com/python/python_ref_dictionary.asp 11 | 12 | Tuple Methods https://www.w3schools.com/python/python_ref_tuple.asp 13 | 14 | Set Methods https://www.w3schools.com/python/python_ref_set.asp 15 | 16 | File Methods https://www.w3schools.com/python/python_ref_file.asp 17 | 18 | Keywords https://www.w3schools.com/python/python_ref_keywords.asp 19 | 20 | Exceptions https://www.w3schools.com/python/python_ref_exceptions.asp 21 | 22 | Glosary https://www.w3schools.com/python/python_ref_glossary.asp 23 | 24 | ''' 25 | 26 | #Module Reference 27 | 28 | ''' 29 | Random Module https://www.w3schools.com/python/module_random.asp 30 | 31 | Request Module https://www.w3schools.com/python/module_requests.asp 32 | 33 | Math Module https://www.w3schools.com/python/module_requests.asp 34 | 35 | CMath Module https://www.w3schools.com/python/module_cmath.asp 36 | ''' 37 | 38 | #https://www.w3schools.com/python/python_reference.asp -------------------------------------------------------------------------------- /02_FileHandling/01_FileHandling.py: -------------------------------------------------------------------------------- 1 | ''' 2 | File Handling 3 | The key function for working with files in Python is the open() function. 4 | 5 | The open() function takes two parameters; filename, and mode. 6 | 7 | There are four different methods (modes) for opening a file: 8 | 9 | ----------------------------------------------------------------------------------------- 10 | "r" - Read - Default value. Opens a file for reading, error if the file does not exist 11 | 12 | "a" - Append - Opens a file for appending, creates the file if it does not exist 13 | 14 | "w" - Write - Opens a file for writing, creates the file if it does not exist 15 | 16 | "x" - Create - Creates the specified file, returns an error if the file exists 17 | ----------------------------------------------------------------------------------------- 18 | In addition you can specify if the file should be handled as binary or text mode 19 | 20 | "t" - Text - Default value. Text mode 21 | 22 | "b" - Binary - Binary mode (e.g. images) 23 | ----------------------------------------------------------------------------------------- 24 | ''' 25 | 26 | #Syntax: To open a file for reading it is enough to specify the name of the file: 27 | 28 | #f = open("demofile.txt") --its equal to-- f = open("demofile.txt", "rt") 29 | 30 | f = open("demofile.txt") -------------------------------------------------------------------------------- /01_PythonTutorial/027_SpecifiVariableType.py: -------------------------------------------------------------------------------- 1 | #Specify a Variable Type 2 | ''' 3 | There may be times when you want to specify a type on to a variable. This can be done with casting. 4 | Python is an object-orientated language, and as such it uses classes to define data types, including its primitive types. 5 | 6 | Casting in python is therefore done using constructor functions: 7 | 8 | int() - constructs an integer number from an integer literal, a float literal (by rounding down to the previous whole number), or a string literal (providing the string represents a whole number) 9 | 10 | float() - constructs a float number from an integer literal, a float literal or a string literal (providing the string represents a float or an integer) 11 | 12 | str() - constructs a string from a wide variety of data types, including strings, integer literals and float literals 13 | ''' 14 | 15 | x = int(1) # x will be 1 16 | y = int(2.8) # y will be 2 17 | z = int("3") # z will be 3 18 | 19 | a = float(1) # x will be 1.0 20 | b = float(2.8) # y will be 2.8 21 | c = float("3") # z will be 3.0 22 | d = float("4.2") # w will be 4.2 23 | 24 | e = str("s1") # x will be 's1' 25 | f = str(2) # y will be '2' 26 | g = str(3.0) # z will be '3.0' 27 | 28 | print(a) 29 | print(b) 30 | print(c) 31 | print(d) 32 | print(e) 33 | print(f) 34 | print(g) 35 | print(x) 36 | print(y) 37 | print(z) 38 | 39 | ''' 40 | Terminal: 41 | 1.0 42 | 2.8 43 | 3.0 44 | 4.2 45 | s1 46 | 2 47 | 3.0 48 | 1 49 | 2 50 | 3 51 | ''' -------------------------------------------------------------------------------- /03_PythonNumpy/001_Introduction.py: -------------------------------------------------------------------------------- 1 | ''' 2 | NumPy Introduction 3 | 4 | What is NumPy? 5 | NumPy is a Python library used for working with arrays. 6 | 7 | It also has functions for working in domain of linear algebra, fourier transform, and matrices. 8 | 9 | NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it freely. 10 | 11 | NumPy stands for Numerical Python. 12 | 13 | Why Use NumPy? 14 | In Python we have lists that serve the purpose of arrays, but they are slow to process. 15 | 16 | NumPy aims to provide an array object that is up to 50x faster than traditional Python lists. 17 | 18 | The array object in NumPy is called ndarray, it provides a lot of supporting functions that make working with ndarray very easy. 19 | 20 | Arrays are very frequently used in data science, where speed and resources are very important. 21 | 22 | Data Science: is a branch of computer science where we study how to store, use and analyze data for deriving information from it. 23 | 24 | ''' 25 | 26 | ''' 27 | 28 | Why is NumPy Faster Than Lists? 29 | NumPy arrays are stored at one continuous place in memory unlike lists, so processes can access and manipulate them very efficiently. 30 | 31 | This behavior is called locality of reference in computer science. 32 | 33 | This is the main reason why NumPy is faster than lists. Also it is optimized to work with latest CPU architectures. 34 | 35 | Which Language is NumPy written in? 36 | NumPy is a Python library and is written partially in Python, but most of the parts that require fast computation are written in C or C++. 37 | 38 | Where is the NumPy Codebase? 39 | The source code for NumPy is located at this github repository https://github.com/numpy/numpy 40 | 41 | ''' 42 | 43 | #github: enables many people to work on the same codebase. -------------------------------------------------------------------------------- /06_MachineLearning/001_GettingStarted.py: -------------------------------------------------------------------------------- 1 | #Machine Learning 2 | 3 | ''' 4 | Machine Learning is making the computer learn from studying data and statistics. 5 | 6 | Machine Learning is a step into the direction of artificial intelligence (AI). 7 | 8 | Machine Learning is a program that analyses data and learns to predict the outcome. 9 | ''' 10 | ''' 11 | Where To Start? 12 | In this tutorial we will go back to mathematics and study statistics, and how to calculate important numbers based on data sets. 13 | 14 | We will also learn how to use various Python modules to get the answers we need. 15 | 16 | And we will learn how to make functions that are able to predict the outcome based on what we have learned. 17 | ''' 18 | 19 | ''' 20 | Data Set 21 | In the mind of a computer, a data set is any collection of data. It can be anything from an array to a complete database. 22 | 23 | Example of an array: 24 | 25 | [99,86,87,88,111,86,103,87,94,78,77,85,86] 26 | ''' 27 | 28 | ''' 29 | Example of a database: 30 | 31 | Carname Color Age Speed AutoPass 32 | BMW red 5 99 Y 33 | Volvo black 7 86 Y 34 | VW gray 8 87 N 35 | VW white 7 88 Y 36 | Ford white 2 111 Y 37 | VW white 17 86 Y 38 | Tesla red 2 103 Y 39 | BMW black 9 87 Y 40 | Volvo gray 4 94 N 41 | Ford white 11 78 N 42 | Toyota gray 12 77 N 43 | VW white 9 85 N 44 | Toyota blue 6 86 Y 45 | ''' 46 | 47 | ''' 48 | By looking at the array, we can guess that the average value is probably around 80 or 90, 49 | and we are also able to determine the highest value and the lowest value, but what else can we do? 50 | 51 | And by looking at the database we can see that the most popular color is white, 52 | and the oldest car is 17 years, but what if we could predict if a car had an AutoPass, 53 | just by looking at the other values? 54 | 55 | That is what Machine Learning is for! Analyzing data and predicting the outcome! 56 | ''' 57 | 58 | ''' 59 | In Machine Learning it is common to work with very large data sets. 60 | In this tutorial we will try to make it as easy as possible to understand the different concepts of machine learning, 61 | and we will work with small easy-to-understand data sets. 62 | ''' 63 | 64 | #https://www.w3schools.com/python/python_ml_getting_started.asp -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is Python? 2 | Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. 3 | #### It is used for: 4 | - web development (server-side) 5 | - software development, 6 | - mathematics, 7 | - system scripting. 8 | 9 | # What can Python do? 10 | 11 | - Python can be used on a server to create web applications. 12 | - Python can be used alongside software to create workflows. 13 | - Python can connect to database systems. It can also read and modify files. 14 | - Python can be used to handle big data and perform complex mathematics. 15 | - Python can be used for rapid prototyping, or for production-ready software development 16 | 17 | # Why Python? 18 | - Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc). 19 | - Python has a simple syntax similar to the English language. 20 | - Python has syntax that allows developers to write programs with fewer lines than some other programming languages. 21 | - Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick. 22 | - Python can be treated in a procedural way, an object-oriented way or a functional way. 23 | 24 | # Good to know 25 | - The most recent major version of Python is Python 3, which we shall be using in this tutorial. However, Python 2, although not being updated with anything other than security updates, is still quite popular. 26 | - In this tutorial Python will be written in a text editor. It is possible to write Python in an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing larger collections of Python files. 27 | 28 | # Python Syntax compared to other programming languages 29 | - Python was designed for readability, and has some similarities to the English language with influence from mathematics. 30 | - Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses. 31 | - Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose. 32 | 33 | # Download Python 34 | Download Python from the official Python web site: https://python.org 35 | -------------------------------------------------------------------------------- /01_PythonTutorial/026_RandomNumber.py: -------------------------------------------------------------------------------- 1 | '''Python does not have a random() function to make a random number, 2 | but Python has a built-in module called random that can be used to make random numbers:''' 3 | 4 | #Import the random module, and display a random number between 1 and 9: 5 | 6 | import random 7 | 8 | print(random.randrange(1, 10)) 9 | 10 | #For more information https://www.w3schools.com/python/module_random.asp 11 | 12 | ''' 13 | seed() Initialize the random number generator 14 | getstate() Returns the current internal state of the random number generator 15 | setstate() Restores the internal state of the random number generator 16 | getrandbits() Returns a number representing the random bits 17 | randrange() Returns a random number between the given range 18 | randint() Returns a random number between the given range 19 | choice() Returns a random element from the given sequence 20 | choices() Returns a list with a random selection from the given sequence 21 | shuffle() Takes a sequence and returns the sequence in a random order 22 | sample() Returns a given sample of a sequence 23 | random() Returns a random float number between 0 and 1 24 | uniform() Returns a random float number between two given parameters 25 | triangular() Returns a random float number between two given parameters, you can also set a mode parameter to specify the midpoint between the two other parameters 26 | betavariate() Returns a random float number between 0 and 1 based on the Beta distribution (used in statistics) 27 | expovariate() Returns a random float number based on the Exponential distribution (used in statistics) 28 | gammavariate() Returns a random float number based on the Gamma distribution (used in statistics) 29 | gauss() Returns a random float number based on the Gaussian distribution (used in probability theories) 30 | lognormvariate() Returns a random float number based on a log-normal distribution (used in probability theories) 31 | normalvariate() Returns a random float number based on the normal distribution (used in probability theories) 32 | vonmisesvariate() Returns a random float number based on the von Mises distribution (used in directional statistics) 33 | paretovariate() Returns a random float number based on the Pareto distribution (used in probability theories) 34 | weibullvariate() Returns a random float number based on the Weibull distribution (used in statistics) 35 | ''' -------------------------------------------------------------------------------- /01_PythonTutorial/045_StringMethods.py: -------------------------------------------------------------------------------- 1 | #String Methods 2 | 3 | ''' 4 | capitalize() Converts the first character to upper case 5 | casefold() Converts string into lower case 6 | center() Returns a centered string 7 | count() Returns the number of times a specified value occurs in a string 8 | encode() Returns an encoded version of the string 9 | endswith() Returns true if the string ends with the specified value 10 | expandtabs() Sets the tab size of the string 11 | find() Searches the string for a specified value and returns the position of where it was found 12 | format() Formats specified values in a string 13 | format_map() Formats specified values in a string 14 | index() Searches the string for a specified value and returns the position of where it was found 15 | isalnum() Returns True if all characters in the string are alphanumeric 16 | isalpha() Returns True if all characters in the string are in the alphabet 17 | isdecimal() Returns True if all characters in the string are decimals 18 | isdigit() Returns True if all characters in the string are digits 19 | isidentifier() Returns True if the string is an identifier 20 | islower() Returns True if all characters in the string are lower case 21 | isnumeric() Returns True if all characters in the string are numeric 22 | isprintable() Returns True if all characters in the string are printable 23 | isspace() Returns True if all characters in the string are whitespaces 24 | istitle() Returns True if the string follows the rules of a title 25 | isupper() Returns True if all characters in the string are upper case 26 | join() Joins the elements of an iterable to the end of the string 27 | ljust() Returns a left justified version of the string 28 | lower() Converts a string into lower case 29 | lstrip() Returns a left trim version of the string 30 | maketrans() Returns a translation table to be used in translations 31 | partition() Returns a tuple where the string is parted into three parts 32 | replace() Returns a string where a specified value is replaced with a specified value 33 | rfind() Searches the string for a specified value and returns the last position of where it was found 34 | rindex() Searches the string for a specified value and returns the last position of where it was found 35 | rjust() Returns a right justified version of the string 36 | rpartition() Returns a tuple where the string is parted into three parts 37 | rsplit() Splits the string at the specified separator, and returns a list 38 | rstrip() Returns a right trim version of the string 39 | split() Splits the string at the specified separator, and returns a list 40 | splitlines() Splits the string at line breaks and returns a list 41 | startswith() Returns true if the string starts with the specified value 42 | strip() Returns a trimmed version of the string 43 | swapcase() Swaps cases, lower case becomes upper case and vice versa 44 | title() Converts the first character of each word to upper case 45 | translate() Returns a translated string 46 | upper() Converts a string into upper case 47 | zfill() Fills the string with a specified number of 0 values at the beginning 48 | ''' 49 | print("String Methods") 50 | 51 | #Note: All string methods returns new values. They do not change the original string. 52 | ''' 53 | Terminal: 54 | String Methods 55 | ''' 56 | #https://www.w3schools.com/python/python_strings_modify.asp 57 | #Learn more about String Methods with our String Methods Reference: https://www.w3schools.com/python/python_ref_string.asp -------------------------------------------------------------------------------- /01_PythonTutorial/052_StringMethods.py: -------------------------------------------------------------------------------- 1 | #String Methods 2 | '''Python has a set of built-in methods that you can use on strings.''' 3 | #Note: All string methods returns new values. They do not change the original string. 4 | 5 | #Upper case the first letter in this sentence: 6 | Capitalize = "hello, and welcome to my world." 7 | 8 | x = Capitalize.capitalize() 9 | 10 | print (x) 11 | 12 | #Make the string lower case: 13 | Casefold = "Hello, And Welcome To My World!" 14 | 15 | x = Casefold.casefold() 16 | 17 | print(x) 18 | 19 | #Return the number of times the value "apple" appears in the string: 20 | Count = "Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro,Pedro." 21 | 22 | x = Count.count("Pedro") 23 | 24 | print(x) 25 | 26 | #Print the word "banana", taking up the space of 20 characters, with "banana" in the middle: 27 | Center = "banana" 28 | 29 | x = Center.center(20) 30 | 31 | print(x) 32 | 33 | #UTF-8 encode the string: 34 | Encode = "My name is Ståle" 35 | 36 | x = Encode.encode() 37 | 38 | print(x) 39 | 40 | #Check if the string ends with a punctuation sign (.): 41 | EndsWith = "Hello, welcome to my world!" 42 | 43 | x = EndsWith.endswith(".") 44 | 45 | print(x) 46 | 47 | #Set the tab size to 2 whitespaces: 48 | WhiteTabs = "H\te\tl\tl\to" 49 | 50 | x = WhiteTabs.expandtabs(2) 51 | 52 | print(x) 53 | 54 | #Where in the text is the word "welcome"?: 55 | Finder = "Hello, welcome to my world." 56 | 57 | x = Finder.find("welcome") 58 | 59 | print(x) 60 | 61 | #Insert the price inside the placeholder, the price should be in fixed point, two-decimal format: 62 | txt = "For only {price:.2f} dollars!" 63 | print(txt.format(price = 49)) 64 | 65 | #Where in the text is the word "welcome"?: 66 | txt = "Hello, welcome to my world." 67 | 68 | x = txt.index("welcome") 69 | 70 | print(x) 71 | 72 | #Check if all the characters in the text are alphanumeric: 73 | txt = "Company12" 74 | 75 | x = txt.isalnum() 76 | 77 | print(x) 78 | 79 | #Check if all the characters in the text are letters: 80 | txt = "CompanyX" 81 | 82 | x = txt.isalpha() 83 | 84 | print(x) 85 | 86 | #Check if all the characters in the unicode object are decimals: 87 | txt = "\u0033" #unicode for 3 88 | 89 | x = txt.isdecimal() 90 | 91 | print(x) 92 | 93 | #Check if all the characters in the text are digits: 94 | txt = "One" 95 | 96 | x = txt.isdigit() 97 | 98 | print(x) 99 | 100 | #Check if the string is a valid identifier: 101 | txt = "2bring" 102 | 103 | x = txt.isidentifier() 104 | 105 | print(x) 106 | 107 | #Check if all the characters in the text are in lower case: 108 | txt = "Hello World!" 109 | 110 | x = txt.islower() 111 | 112 | print(x) 113 | 114 | #Check if all the characters in the text are numeric: 115 | txt = "565543" 116 | 117 | x = txt.isnumeric() 118 | 119 | print(x) 120 | 121 | #Check if all the characters in the text are printable: 122 | txt = "Hello! Are you #1?" 123 | 124 | x = txt.isprintable() 125 | 126 | print(x) 127 | 128 | #Check if all the characters in the text are whitespaces: 129 | txt = " " 130 | 131 | x = txt.isspace() 132 | 133 | print(x) 134 | 135 | #Check if each word start with an upper case letter: 136 | txt = "Hello, and welcome to my world!" 137 | 138 | x = txt.istitle() 139 | 140 | print(x) 141 | 142 | #Check if all the characters in the text are in upper case: 143 | txt = "THIS IS NOW!" 144 | 145 | x = txt.isupper() 146 | 147 | print(x) 148 | 149 | #Join all items in a tuple into a string, using a hash character as separator: 150 | myTuple = ("John", "Peter", "Vicky") 151 | 152 | mySeparator = " and " 153 | 154 | x = mySeparator.join(myTuple) 155 | 156 | print(x) 157 | 158 | #Return a 20 characters long, left justified version of the word "banana": 159 | txt = "banana" 160 | 161 | x = txt.ljust(20) 162 | 163 | print(x, "is my favorite fruit.") 164 | 165 | #Lower case the string: 166 | txt = "HELLO FRIENDS" 167 | 168 | x = txt.lower() 169 | 170 | print(x) 171 | 172 | #Remove spaces to the left of the string: 173 | txt = " banana " 174 | 175 | x = txt.lstrip() 176 | 177 | print("of all fruits",x,"is my favorite") 178 | 179 | #Create a mapping table, and use it in the translate() method to replace any "S" characters with a "P" character: 180 | txt = "Hello Sam!"; 181 | mytable = txt.maketrans("Sam", "Paa"); 182 | print(txt.translate(mytable)); 183 | 184 | #Partitions 185 | txt = "I could eat bananas all day" 186 | 187 | x = txt.partition("bananas") 188 | 189 | print(x) 190 | 191 | #Replace the word "bananas": 192 | txt = "I like bananas" 193 | 194 | x = txt.replace("bananas", "chocolat") 195 | 196 | print(x) 197 | 198 | #Where in the text is the last occurrence of the string "casa"?: 199 | txt = "Mi casa, su casa." 200 | 201 | x = txt.rfind("casa") 202 | 203 | print(x) 204 | 205 | #Where in the text is the last occurrence of the string "casa"?: 206 | txt = "banana" 207 | 208 | x = txt.rjust(20) 209 | 210 | print(x, "is my favorite fruit.") 211 | 212 | #rpartition 213 | ''' 214 | Search for the last occurrence of the word "bananas", and return a tuple with three elements: 215 | 216 | 1 - everything before the "match" 217 | 2 - the "match" 218 | 3 - everything after the "match" 219 | ''' 220 | txt = "I could eat bananas all day, bananas are my favorite fruit!" 221 | 222 | x = txt.rpartition("bananas") 223 | 224 | print(x) 225 | 226 | #rsplit: Split a string into a list, using comma, followed by a space (, ) as the separator: 227 | txt = "apple, banana, cherry" 228 | 229 | # setting the maxsplit parameter to 1, will return a list with 2 elements! 230 | x = txt.rsplit(", ", 1) 231 | 232 | print(x) 233 | 234 | #Remove any white spaces at the end of the string: 235 | txt = " banana " 236 | 237 | x = txt.rstrip() 238 | 239 | print("of all fruits", x, "is my favorite") 240 | 241 | 242 | 243 | 244 | ''' 245 | Terminal: 246 | Hello, and welcome to my world. 247 | hello, and welcome to my world! 248 | 15 249 | banana 250 | b'My name is St\xc3\xa5le' 251 | False 252 | H e l l o 253 | 7 254 | For only 49.00 dollars! 255 | 7 256 | True 257 | True 258 | True 259 | False 260 | False 261 | False 262 | True 263 | True 264 | True 265 | False 266 | True 267 | John and Peter and Vicky 268 | banana is my favorite fruit. 269 | hello friends 270 | of all fruits banana is my favorite 271 | Hello Paa! 272 | ('I could eat ', 'bananas', ' all day') 273 | ''' 274 | #https://www.w3schools.com/python/python_strings_methods.asp --------------------------------------------------------------------------------