Changes between Version 56 and Version 57 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 7:45:57 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v56 v57 207 207 * `sum(iterable)`: Sums all the numbers in the list ''iterable''. 208 208 * `<string>.isdigit()`: Strings and some other variable types like lists have some special functions just for them, called methods. This one returns true of all of the digits in the string are numbers, others are [[https://docs.python.org/3/library/stdtypes.html#string-methods|here]]. '123' would return ''True'', "Cat" would return ''False''. Handy for validation. You call them *on* the variable itself, and it has to have a value before you can call these methods. 209 * 'int(string)': Converts an string to a number (so you can do things like math on it). 209 210 210 211 Here's some examples of how they're used (don't forget to look at earlier lessons for range() and print(). … … 227 228 f = e.isdigit() 228 229 print(f) #Result is True 230 231 g = int("123") 232 print(g) #Result is 123 233 229 234 }}} 230 235 231 236 Try running these yourself, making sure the results are as expected. 232 237 233 You can even combine these functions with control structures to do some interesting stuff . For example, try running this (entering values for x and why when prompted. Try putting in non-numericvalues too):238 You can even combine these functions with control structures to do some interesting stuff, and even nest them. For example, try running this (entering values for x and why when prompted. Try putting in non-numeric or decimal values too): 234 239 235 240 {{{ … … 241 246 while not y.isdigit(): 242 247 y=input("Enter y-->") 243 z = pow( x,y)248 z = pow(int(x),int(y)) 244 249 if z > 100: 245 250 print("That's-a big number!")