Please enable JavaScript.
Coggle requires JavaScript to display documents.
Python - Coggle Diagram
Python
Built in methods
-
-
-
-
-
print("Mohammed has {} balloons".format(27)) # adds the var or object 27 into the {} as a sub. Can take multiples for ex; print("Does your {} {}?".format(animal, action))
str.split() # default is to split a string up by spaces into an array or list. You can add the first option which is a separator and the max split argument which is a int.
-
-
loops
for
range ex:
-
-
-
-
common errors
ZeroDivisionError: division by zero." This is an error message that you saw earlier in this lesson. What did this error message indicate to us? You can look back in the Quiz: Arithmetic Operators section to review it if needed.
SyntaxError: unexpected EOF while parsing" Take a look at the two lines of code below. Executing these lines produces this syntax error message - do you see why? greeting = "hello"
print(greeting.upper
This message is often produced when you have accidentally left out something, like a parenthesis. The message is saying it has unexpectedly reached the end of file ("EOF") and it still didn't find that right parenthesis. This can easily happen with code syntax involving pairs, like beginning and ending quotes also.
"TypeError: len() takes exactly one argument (0 given)" This kind of message could be given for many functions, like len in this case, if I accidentally do not include the required number of arguments when I'm calling a function, as below. This message tells me how many arguments the function requires (one in this case), compared with how many I gave it (0). I meant to use len(chars) to count the number of characters in this long word, but I forgot the argument.
chars = "supercalifragilisticexpialidocious"
len()
dictionary
can be a string, int or float for a key ex: population = {'Shanghai': 17.8, 'Istanbul': 13.3, 'Karachi': 13.0, 'Mumbai': 12.5 }
-
-
-
-
-
-
-