Input Validation Tutorial for Python

Publié le: 14 février 2024
sur la chaîne: Byte_Logic
35
1

In this video I'll be covering the try except logic in python. I will be using the templates discussed in our previous videos but don't worry, these concepts can be demonstrated on their own! I'll leave a copy paste template below (as usual).

The Try except logic can be used for may things; however, I seem to use it most for input validation. In my work and personal life, I use this small but effective logic structure as a soft guide for anyone else trying to run my code.

There are other uses as well; the except clause can be modified for greater error reporting.

Challenge:

Next time you're troubleshooting code, try putting sections of it in a try except clause BUT modify the except clause so that it reads as the following:

except Exception as exception:
print(exception)

This will give you a better explanation of what is breaking in your code an you can quickly narrow down your mistakes.

===============================================
global var1

Validation
validation2 = True

while validation2:
try:
var1 = input()
validation2 = False
except:
validation2 = True
==============================================

Please feel free to ask me any questions!

Link below for the template video \/
   • Habits That Will Set You Apart In The Pyth...   - the template itself
   • Python | THE SECRET SAUCE!!   - the looping logic video (very useful)


Sur cette page du site, vous pouvez voir la vidéo en ligne Input Validation Tutorial for Python durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Byte_Logic 14 février 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 35 fois et il a aimé 1 téléspectateurs. Bon visionnage!