Python 3 Programming Tutorial - Common errors

sentdex · Beginner ·🛠️ AI Tools & Apps ·12y ago

Key Takeaways

This video covers common errors in Python 3 programming, including typos, indentation issues, and syntax errors, and provides basic debugging techniques to resolve these issues using tools like Python 3 interpreter and a text editor.

Full Transcript

hello everybody and welcome to another Python 3 Basics video in this video we're going to be discussing some of the basics to debugging in my videos I get a lot of questions for help where people have errors and they're not really sure where the problem is but if they use some basic and simple debugging they'd realize how obvious the answer really is so most of the time the problem is a typo followed very closely to a misunder understanding of indentation and standards but usually it's a typo um and I guess they just don't understand what the error is saying but every time you see this error it's like oh you should just automatically be like oh I must have type it somewhere so if you don't know what standards are standards are basically how we organize our code so with python unlike most languages you define blocks of code uh like functions with indentation so Define a function and here is your functions code everything goes in here and then whenever the function's done it's just literally um you just unindent and you start new stuff so this is the function BL block and this is not the function block and when people start getting into trouble they do stuff like this and that gives them um problems uh with syntax now there's obviously a lot of Inc uh in-depth common issues that you might find from time to time and you can find some more debugging videos uh by searching for debugging in my channel uh for now I'm just going to keep these uh examples pretty basic the first error that we're going to discuss is name error is not defined so uh an example of this one is going to be variable equals 55 print ver iable so we've obviously typo a variable and we go to run and we get you know uh name error variable is not defined and this sometimes drives people crazy especially if maybe this is variable and this is the typoe variable and they say they see name Arrow variable is not defined but they know they just defined it like they just defined it so they start freaking out but almost as always this is the case it's they've just simply typoed variable now we can talk about indentation issues here's an example of something you I've seen a few times uh task and then they come down here uh task two and then they start typing um whatever um and you get expected and indented block um and this just means that it expected some sort of indentation here uh another time uh you'll see something similar uh when it's expecting another indentation uh yet slightly different is say you've got print or better yet a variable where it says x equals um actually first we'll show print uh print and people maybe print hello there then they come down here and immediately you should recognize that oh something is wrong because python has indented me and I don't know why and it's for the reason before where you could put something something like this and then more stuff um but then some people continue on and you'll have print um f let's say and you run and it just says invalid syntax well that's not very helpful to some people especially if it's not going to highlight where your invalid syntax is but again generally it's because you didn't close something off now another common one that people are going to get is going to be the following it's going to be EOL while scanning string literal um and this happens a lot if say you've got a variable and the variable is a string of text and like this string of and then print X and we'll run you get e while scanning string literal and the reason why you get this is this string never finished yet we started a new line and he's very frustrated so you'd have to close this off now those are just some of the common things uh and I realized Maybe that was just really painfully slow for some of you guys um but this actually catches a lot of people I'd say at least 90% of the um problems that people have they you know if they leave a comment and they're having a debugging problem they've got something wrong with their script they can't figure it out honestly 90% of the time uh it's one of these things and of that 90% probably 90% of the time it's just a simple typo so anyway thought it'd be a good idea to go ahead and cover that uh as far as you know name or you know variable not defined uh almost always a typo um so sometimes people just don't understand what the error is even saying to them so they don't even know what to think so anyway that's going to conclude this video hopefully that was helpful for some of you guys as always thanks for watching thanks for all the support subscriptions and until next time

Original Description

In this video we'll be discussing some of the basics to debugging. In my videos, I get a lot of questions for help where people have errors and are not sure what the problem is. If they used some extremely simple debugging, they'd realize how obvious the answer is. Most of the time, the problem is a typo, followed closely by a misunderstanding of indentation and standards. Standards how are how you organize your code. With python, unlike most languages, you define blocks of code, like functions, by indentation. Most python editors will automatically indent for you where it is necessary. With this, if you are ever coding along and find python automatically indenting you where you don't think it should, this should raise a flag for you to figure out. There are some more in-depth common-issues that you'll find from time to time, you can find more debugging videos by searching for debugging in my channel. For now I will just keep these ones basic. The first error we'll discuss is the NameError: is not defined. As obvious as this might appear to you, this gets people amazingly frequently. Just learn to recognize the "is not defined" as a high chance that you have typoed the definition of the variable or when you are calling it. Basically, you typo-ed somewhere. Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/ Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches basic debugging techniques in Python 3, covering common errors such as typos, indentation issues, and syntax errors, and provides examples of how to resolve these issues using a text editor and the Python 3 interpreter.

Key Takeaways
  1. Identify the error message and understand what it means
  2. Check for typos in variable names and function calls
  3. Verify indentation is correct and consistent
  4. Use a text editor to write and edit Python code
  5. Run the code using the Python 3 interpreter to test for errors
💡 Most common errors in Python 3 are due to simple typos or indentation issues, and can be resolved using basic debugging techniques.

Related AI Lessons

Up next
I Asked ChatGPT to Apply to 500 Jobs (8 Interviews in 48 Hours)
Sabrina Ramonov 🍄
Watch →