# MLE_VISOR2 Week 1 Note ## CONSTANTS, VARIABLES, DATA TYPES ## 1. CONSTANTS and VARIABLES: ##### A constant is a type of variables that its value can't be change while with variables we can change what data its store in the memory ##### Ex: 2021 is a constant: ``` print(2021) ``` year is a variable: ``` year = 'This is the current year' print(year) year = 2021 print(year) ``` ## 2. DATA TYPES: You can check your data types using type() ``` type(4) type(4.41) type('Lalalala') type(True) ``` ### 1. NUMBERS: ##### Numerical data types can belong to 2 different numerical types: int and float ``` type(4) #return int type(4.41) #return float ``` We can also conver between these 2 data types ``` int(4.41) #return 4 float(4) #return 4.0 ``` Mathematics operation for numbers: we can assign a number to a variable and calculate with it ``` score = 4 score + 1 #plus score - 2 #minus score * 2 #multiplication score/2 #divine score % 2 #find the remainder score//2 #interger division ``` ### 2. Strings: ##### String is a sequence of characters surround by quotes You can use single quotes, double quotes (in case the string containt single quotes) and triple quotes (to have multiple lines in string) ``` print('CoderSchool') print("I'm tired!!!") print('''I'm still tired but you need to read it multiple lines to get tired too :D''') ``` ##### Indexing allows you to access invidual characters by using a numeric value. ###### The formula is W[start:stop:step] - 'start' is the index of the first character you want to find (default by 0, in Python we start counting at 0) - 'stop' is the index of the last character you want to find (defaul by the length of the string) - step is the increment you want in the index (default by 1). ``` x = 'CoderSchool' x[1:4:2] x[:5] x[:] ``` ##### String is also immutable, which means you can't do this ``` #change the fourth character of x to C and get 'CodCrSchool' x = 'CoderSchool' x[3] = 'C' #to do this you will need to change the whole string x = 'CodCrSchool' x[3] #pretty tired :( ``` ### 3. Boolean: ##### Boolean is the result when you compare two variable/constants and it will return True/False. However you can't compare two variables with different data types ``` a = 5 b = 6 a < b #return True a > b #return False ``` ##### True will be equal to 1 and False will be equal to 0