click below
click below
Normal Size Small Size show me how
Programming #1
| Question | Answer |
|---|---|
| What is command "finally" when handeling exceptions | no matter if try or except is used, finally is executed every time |
| What is "is" operator | similiar to ==, but checks if object same are #a=1 & b=1 #a==b >>> True #a is b >>> False |
| What are multiline strings | """ at beginning and end text can go over multiple lines of the code |
| How to calculate 2^10 in Python (2) | 1, 2**10 2, 2E10 |
| How to use reverved characters like ", ', \ | #with \ infront of the character print(\"Hello\" ) >>> "Hello" |
| What happen if we convert booleans into integers | True >>> 1 False >>> 0 |
| How can we find out if we can convert string into integer without error | text="13345" text.isdigit() >>> True ! if "." inside like float that returns false! |
| What are command to search first occurance of an letter (3) | 1, ("x").index("text") #if not in text returns an error 2, ("x").find("text") #if not in text returns -1 3,("x").rfind("text") like find but search for last occurance |
| How do we make command for if and else in one line | "value if true" if CONDITION else "value if false" # status="Adult" if age>=18 else status="Minor" print(status) |
| What if the third argument in for a in range | the third argument is which each step should work for nr in range (1,11,2) >>>>1,3,5,7,9 |
| How to change that print doesnt go to next line | print("text",end="") #default is print("text",end="\n") |
| What can we set number of decimals in number variable with f" " | pi=3.14189 print(f"{pi:.2f}") |
| What is difference between extend and append if we want to add list to list | extend >>> iterate items and add every single into list append >>> add the whole list into list |
| How can we delete items from list if we know the name | the_list.remove("name") |