Python Learning Check List - Key concepts
| Important Concepts | Notes | Program Examples | ||
| Variable types | ||||
| strings numbers (integer, float) converting : strings to number numbers to strings |
str_val = "Hello" convert to int:: int_val = int(str_val) |
|||
lists |
my_list = [ 1, 2,"word" ] print(my_list[0], my_list[2]) for val in list: print(val) list_length = len(my_list) |
Click Here | ||
| dictionaries | dict_1 = {} Click Here dict_1["first"] = "Harry" dict_1["last"] = "Baya" print(dict_1["first"].dict_1["last"] each "key: has an assoicate values |
Click Here | ||
| boolean variables | bool_val = True, bool_ val = False, bool_ val = (a > b) if (bool_val): print ("Is true") |
Click Here | ||
| print ("Integer is ",int_val,"\n") print(str_1+"is older than"+str_2) print("enter a number: ", end= "") |
Click Here | |||
| if statement (conditional) | if ( str_val == "house): if (val <= 24): |
Click Here | ||
| Loops | ||||
| while loop | while (count < 20): | Click here for "while loops" | ||
| for loop | for num in list_var: for val in range(100) for val in range(2, 100) |
Click here for "for loops" | ||
| User Input (from keyboard) | val= sys.stdin.readline() note: reads in a string int_val = int(val) |
Click Here | ||
| Python functions ( aka methods, subroutines ) | ||||
| File input and output (reading from, writing to) | ||||
| create file to write in write to file |
||||
| open file , for read only read from file |
||||
| open file for read or write read from file write to file |