Built-in Functions - Python 3 Programming Tutorial p.4

sentdex · Beginner ·🛠️ AI Tools & Apps ·7y ago
Skills: Prompt Craft60%

Key Takeaways

The video tutorial covers Python 3 programming, focusing on built-in functions such as enumerate, abs, and zip, and demonstrates their usage in game development, specifically in creating a tic-tac-toe game map and analyzing game state for win conditions.

Full Transcript

what's going on everybody and welcome to part 4 of the Python 3 basics tutorial in this tutorial we are making a tic-tac-toe in order with Python in order to learn the Python 3 basics where we left off we've got our you know our our grid that is gonna be our tic-tac-toe sort of game map and now what we want to do is visualize for the user a way for them to to be able to say hey I want to play on such-and-such row in such-and-such column or you know such as such column or such-and-such row and so on so there's a few options that we have from easy to hard that we could do but basically we probably want to have like numbers or letters at the top and then maybe numbers or letters on the side so one a or one one or or or whatever so so the first thing is like what if we just wanted to like print some numbers up at the top how might we how might we get around doing that well one option is super simple we could just simply do like a print statement and say 0 1 2 now it's not gonna be lined just right so let's just run it really quick ok so we probably really just need one space here let's run it again and that appears to be pretty well aligned so if you wanted to move 0 1 2 you know for the actual row name all right so there's be a column name you could specify that column by 0 1 or 2 now what about on the other side like how would we do it over here right because in it's in this print row that we would need the number well there's a variety of things that we could do so one of the ways a basic programmer might do this is with a starting with like some sort of counter so you could say count equals zero and then in print you can continue to just print many things at a time so print row well you could instead prints we could print count comma row so this will print count add a space and then print the row so for example if I just run this now it's you know all zeros and we can see our top thing is messed up so let's add look probably two more spaces there that should do it yeah so now how can we get count to go up well all we need to do is do count and you could say count equals count plus one that's one way you could do it and so we could run that real quick and see okay 0 1 2 on that left-hand side for the each each row the other option is a slightly more condensed plus equals one this does the exact same thing as count equals count plus one okay pretty cool now this is not really the best way to do it in terms of you know being the best Python programmer you could be but it does get the job done that said Python comes with a huge assortment of what are called built-in functions so let's do Python 3 built-in functions and let's just click on that that first one and you can see here there's quite a few built-in functions each one does something special from abs which is just absolute value all the way down to I'm gonna skip important just do zip zip is a way to at least usually what you do a zip is combine a couple of lists we can we I don't we might use zip later but anyways all of these are super useful but these built-in functions most of them are written in Python and so you don't have to know them so like I was saying before built-in functions are like more tools that you can add to your tool set but do you need them no you don't have to learn every single one but once in a while just like I said before you know you might want to come in and look at the built-in function just get reminded at what all is available to you and maybe try to learn a new one once in a while or something and there's really there is a lot here but it doesn't take long to learn what all of these do so anyway one of the built-in ones that we're going to use is enumerate we could click on it we can learn more but basically all it does is it iterates as you iterate over something innumerate returns both the index value and the value of the thing you're iterating over now an index value is the thing in a list so two let's just write it out first I think I'm trying to say which would be better I don't know if I'm gonna write it out or not I think I will and they maybe delete it all that's probably will do so so you can do four count comma row in enumerate game and then let's get rid of this count here and then we'll get rid of this count here so now we're gonna iterate over the rows in game now iterating now what is each row in game remember each row is this little bit this bit in this bit and then you could iterate over the values in the rows as well and I could show that in a moment but first let's go ahead and print this one out as you can see we have the same thing so one thing to take note of is initially your index value starts at zero everything in programming starts at zero not this is Row 1 2 3 this is row 0 Rho 1 Rho 2 so sometimes you'll hear me refer to things as the first if element because it's not the first element it's the first tooth element so or the zeroeth element and so on so sometimes I'll make those distinctions just because it can sometimes get confusing but it really most that time I refer to something I'm referring to its index value so so those are at least that's one of the built-in functions in in Python so just to show you what I meant to sometimes this stuff can be hard to visualize at first I'm sure many of you guys already have it you understand as you iterate over the rows okay cool I've got that well but you also could iterate over the elements in each because this is a list of lists so when we do a for something in that list of lists you've got list 1 and then the list 2 so when you iterate over a list of lists the first thing that you're iterating over is the lid but if you you could take that further and iterate over the items in those lists with just another four so as a quick note if you want to leave something in your code or write something in your code you can do what's called a comment a single line comment is a pound or a hashtag depending on when you were born so so anyways that's how you comment something out a comment is just for people reading your code you to take notes the programming language doesn't care what you put in there it doesn't have to be Python 3 syntax you can put anything in a comment so that's a single line comment if you want to make multi-line comments you can use triple quotes multi-line comments okay that's a multi-line comment so anyways now that we've commented those things out we won't see them anymore so now let's instead say for item in row because remember row being a temporary value right now it's the store of like for example this or this it's all zeros but you could iterate over them and print item and as you can see it's just a bunch of zeros nothing special anyways that's I think that's a good spot for us to stop I am going to now get rid of our comment get rid of this get rid of this and this will now throw an error so I'm gonna get rid of that and let me make sure everything looks correct it does okay so now what I'm gonna do is also at some point we probably should make this like a b c or something like that i think that starts to make a little more sense but you can do whatever you want I just think that's probably less likely to cause problems later but we'll talk about it so anyways I'm gonna leave me here and now moving forward we've at least got a game map so I can run it again we now know a user could say okay I want to play a 0 or B 2 so if we typed in you know it's like if we allow input from the and they say baby - we can all agree that's going to be that spot right there so what we need to start being able to do is use our programming to somehow manipulate that exact spot on the on the game board both so we can do analysis with our programming to decide hey has anybody won can they even move there but also to visualize it for the user after they've made the move so that's going to require indexing and and might as well cover slices at the same time so that's what we're gonna talk about in the next video if you have questions comments concerns whatever feel free to even below join the discord otherwise I will see you guys and girls in the next video

Original Description

Learning how to use built-in functions, and where to find more! https://docs.python.org/3/library/functions.html Playlist: https://www.youtube.com/playlist?list=PLQVvvaa0QuDeAams7fkdcwOGBpGdHpXln #python #programming #tutorial
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 tutorial teaches Python 3 programming, focusing on built-in functions and their usage in game development, specifically in creating a tic-tac-toe game map and analyzing game state for win conditions. It covers iterating over lists, using enumerate, and indexing and slicing. The tutorial provides a practical example of using Python for game development.

Key Takeaways
  1. Print a list of numbers 0 1 2
  2. Use a counter to print column names
  3. Increment the counter by 1
  4. Use enumerate to iterate over a list
  5. Write out a list with enumerate function
  6. Iterate over rows in a list of lists
  7. Iterate over elements in each row
  8. Print out values in a row
  9. Use comments to leave notes in code
  10. Create a game map
💡 The enumerate function returns both index value and value of the thing being iterated over, and indexing and slicing can be used for manipulation in game development.

Related AI Lessons

Up next
How to Open HPL Files (HP-GL Plotter)
File Extension Geeks
Watch →