Updated code examples to Python 3 (#20765)
This commit is contained in:
		
				
					committed by
					
						 Christopher McCormack
						Christopher McCormack
					
				
			
			
				
	
			
			
			
						parent
						
							d81d8c77b5
						
					
				
				
					commit
					575cf064af
				
			| @@ -10,24 +10,26 @@ To solve this problem in python we can use `try` and `except` | |||||||
|  |  | ||||||
| Example: | Example: | ||||||
|  |  | ||||||
| ```shell | ```python | ||||||
| >>> try: | try: | ||||||
| >>> . . . print "this is not a string "+1 |     print("this is not a string " + 1) | ||||||
| >>> except: | except: | ||||||
| >>> . . . print "error" |     print("error") | ||||||
| error |  | ||||||
| ``` |  | ||||||
| and if you want to get error messages in more detail from your code, you can add arguments `except Exception as err` |  | ||||||
|  |  | ||||||
| ```shell | >>> error | ||||||
| >>> try: | ``` | ||||||
| >>> . . . print "this is not a string "+1 | And if you want to get error messages in more detail from your code, you can add arguments `except Exception as err` | ||||||
| >>> except Exception as err: |  | ||||||
| >>> . . . print "error:\n"+str(err) | ```python | ||||||
| error: | try: | ||||||
| cannot concatenate 'str' and 'int' objects |     print("this is not a string " + 1) | ||||||
|  | except Exception as err: | ||||||
|  |     print("error:\n" + str(err)) | ||||||
|  |      | ||||||
|  | >>> error: | ||||||
|  | >>> must be str, not int | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| More Information: | More Information: | ||||||
|  |  | ||||||
| Errors and Exceptions <a href='https://docs.python.org/2/tutorial/errors.html' target='_blank' rel='nofollow'>documentation</a>. | Errors and Exceptions <a href='https://docs.python.org/3.6/tutorial/errors.html' target='_blank' rel='nofollow'>documentation</a>. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user