Tutorial 2 “Rules and Patterns”
Transcript of Tutorial 2 “Rules and Patterns”
![Page 1: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/1.jpg)
Tutorial 2 “Rules and Patterns”
![Page 2: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/2.jpg)
![Page 3: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/3.jpg)
![Page 4: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/4.jpg)
![Page 5: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/5.jpg)
![Page 6: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/6.jpg)
![Page 7: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/7.jpg)
![Page 8: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/8.jpg)
![Page 9: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/9.jpg)
![Page 10: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/10.jpg)
![Page 11: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/11.jpg)
![Page 12: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/12.jpg)
![Page 13: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/13.jpg)
![Page 14: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/14.jpg)
![Page 15: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/15.jpg)
![Page 16: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/16.jpg)
![Page 17: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/17.jpg)
#### QUICK SUMMARY OVERVIEW
#### VARIABLES#### Integer: Ganzzahl typecast: int(5.6789) -> Result: 5#### Float: Gleitkommazahl typecast: float(5) -> Result: 5.0#### String: Zeichenkette typecast: str(5.6789) -> Result: "5.6789"######## to find out the type of a variable: type(var)
#### LISTS#### defining lists:#### mylist = [ 1, 3, 2, 4, 7]#### kollegen=["andi", "richard", "urs", "gregor", "eszter", "fabian"]#### #### kollegen[0] / mylist[0] -> first element#### kollegen[1] / mylist[1] -> second element#### kollegen[-1] / mylist[-1] -> last element#### kollegen[0:4] / mylist[0:4] -> list with first through fourth (not fifth!) element#### kollegen[-3:] / mylist[-3:] -> list with all elements starting from third last######## NOTE: this syntax also works on Strings#### my_str = "hello python"#### my_str[0] -> "h"#### my_str[-3:] -> "hon"
#### LOOPS#### Repeat a block statement until condition is reached#### #### WHILE LOOP#### i=0 # variable needs to be set befor loop#### while (i < 10): # condition in parantheses is evaluated as true or false#### print i # block statement is indented#### i=i+1 # if variable is not incremented, loop will run forever!!!######## EQUIVALENT FOR LOOP (no initializing or explicit incrementing necessary!)#### for i in range(10):#### print i # block statement is indented######## for name in kollegen:#### print name
![Page 18: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/18.jpg)
![Page 19: Tutorial 2 “Rules and Patterns”](https://reader031.fdocuments.in/reader031/viewer/2022013001/61cabb8289e9ea7a456206d1/html5/thumbnails/19.jpg)