This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = 1004001 | |
value = 15.50 | |
msg = "This action is not allowed" | |
print(f"Error {code:10d}") # code will occupy 10 characters | |
## 'Error 1004001' | |
print(f"Error {code:#X}") # code will be shown as hexa, uppercase, with 0X prefix | |
## 'Error 0XF51E1' | |
print(f"Value: {value:.4f}") # value will have 4 digits after decimal point | |
## 'Value: 15.5000' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> f"Error {code}: {msg}" | |
'Error 1004001: This action is not allowed' | |
>>> f"Error {code:#x}: {msg}" | |
'Error 0xf51e1: This action is not allowed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f"Error {code}: {msg}" | |
## 'Error 1004001: This action is not allowed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Error {}: {}".format(code, msg) | |
## 'Error 1004001: This action is not allowed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> "Error %d: %s" % (code, msg) | |
'Error 1004001: This action is not allowed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msg = "This action is not allowed" | |
details = "Please, talk to your admin" | |
code = 1004001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
print('ok') | |
except ValueError: | |
print('value error') | |
except: | |
print('other error') | |
else: | |
print('everything went fine') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
print('some danger code') | |
except ValueError: | |
print('a value error occurred') | |
except: | |
print('other error happened') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
correct_password = 'supersecret!' | |
for i in range(3): | |
password = input('Please, type your password:') | |
if password == correct_password: | |
break | |
else: | |
print('Sorry! You entered the wrong password many times!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
correct_password = 'supersecret!' | |
tries = 3 | |
while tries > 0: | |
password = input('Please, type your password:') | |
if password == correct_password: | |
break | |