TubeSum

Build a Random Password Generator in Python — Step-by-Step Guide & Transcript

Random Password Generator - Python Basics with Sam

0h 57m video Published Nov 3, 2020 Transcribed Aug 10, 2026 F freeCodeCamp.org
Beginner 10 min read For: Beginners learning Python who want to build a practical project and understand basic modules, functions, and string manipulation.
AI Trust Score 70/100
⚠️ Average / Some Fluff

"The title promises a random password generator tutorial, and the video delivers exactly that, with some bonus content, though the live stream format includes some off-topic chatter."

AI Summary

In this live stream, Sam from Python Basics, hosted by freeCodeCamp, walks through building a random password generator in Python. The session covers using the random and string modules, implementing weak, strong, and very strong password scenarios, and handling key concepts like default arguments, docstrings, and list shuffling. Sam also includes bonus tips on zip/unpacking and exploring Python's help system.

[02:00]
Introduction and Stream Setup

Sam introduces the stream, mentions it's live stream 12, and thanks freeCodeCamp and moderator Cardinal. He notes that micro videos for all topics are available on his channel and a playlist on freeCodeCamp's YouTube.

[04:55]
Modules Needed: random and string

To build the password generator, Sam imports the random module for generating random choices and the string module to access predefined character sets like ascii_letters, digits, and punctuation.

[05:24]
Understanding random and Pseudo-Randomness

Sam explains that random numbers are actually pseudo-random because computers are based on logic and humans tend to repeat digits. He highlights the random.choice and random.shuffle functions, noting shuffle works in place and returns None.

[08:06]
Exploring string Module Constants

Sam demonstrates string.ascii_lowercase, ascii_uppercase, ascii_letters, digits, and punctuation. He explains ASCII as the characters a computer knows, with 52 letters (26 lowercase + 26 uppercase).

[11:43]
Creating the Function with Default Arguments

The function is named 'password' and takes arguments: length (positional), num (default False), and strength (default 'weak'). Sam explains default/optional arguments using print's 'end' parameter as an example.

[14:33]
Writing a Docstring

Sam writes a docstring to document the function's parameters: length of password, num for including numbers, and strength with options weak, strong, and very. This helps users understand how to call the function.

[17:30]
Implementing Weak Password Logic

For weak passwords, Sam uses only lowercase letters. He creates a loop that appends random.choice(lower) to the password string for the given length, then returns the password.

[24:45]
Adding Numbers to Passwords

If num is True, Sam reduces the length by 2 and adds two random digits at the beginning. He emphasizes incremental development: write one functionality, test it, then move on.

[27:20]
Strong and Very Strong Scenarios

For strong, Sam includes both uppercase and lowercase letters. For very, he adds punctuation and uses random.randint to determine a random number of digits (2-4), making the password more unpredictable.

[31:42]
Shuffling and Joining the Password

To avoid predictable patterns (digits at the start), Sam converts the password to a list, uses random.shuffle (which returns None), and then joins the list back into a string using ''.join().

[44:19]
Bonus: Zip and Unpacking

Sam demonstrates zip to combine two lists (students and grades) into tuples, and uses the splat (*) operator to unpack them back into separate lists.

[47:35]
Bonus: String Methods and Help System

Sam shows string methods like center() and is numeric checks, and emphasizes using Python's help() prompt to explore functions, keywords, and documentation interactively.

Sam successfully builds a functional random password generator with three strength levels, reinforcing best practices like incremental development and using docstrings. He also shares bonus tips on zip/unpacking and leveraging Python's built-in help system for self-learning.

Mentioned in this Video

Tutorial Checklist

1 04:55 Import the random and string modules.
2 11:43 Define a function named 'password' with parameters: length, num (default False), and strength (default 'weak').
3 14:33 Write a docstring explaining the parameters and usage.
4 17:30 For weak strength, use string.ascii_lowercase and loop to append random.choice(lower) to the password string for the given length.
5 24:45 If num is True, reduce length by 2 and add two random digits using random.choice(string.digits).
6 27:20 For strong strength, use string.ascii_letters (both cases) and repeat the same logic as weak.
7 34:09 For very strength, use random.randint(2,4) to get a random number of digits, add that many digits and punctuation, then fill the rest with letters.
8 31:42 Convert the password string to a list, use random.shuffle() to shuffle it, then join back into a string with ''.join().
9 38:59 Test the function with different lengths and strengths, e.g., password(15, num=True, strength='very').

Study Flashcards (10)

What is the difference between random.choice and random.shuffle?

easy Click to reveal answer

random.choice selects a random element from a non-empty sequence, while random.shuffle shuffles a list in place and returns None.

07:05

What does the string module provide?

easy Click to reveal answer

It provides predefined character sets like ascii_letters, ascii_lowercase, ascii_uppercase, digits, and punctuation.

08:06

What is a docstring and why is it used?

easy Click to reveal answer

A docstring is a documentation string enclosed in triple quotes that describes a function's parameters and usage.

14:33

What is the default value of the 'num' parameter in the password function?

easy Click to reveal answer

The default value is False, meaning numbers are not included unless explicitly set to True.

25:00

Why does random.shuffle return None?

medium Click to reveal answer

Because shuffle operates in place, modifying the list directly and not creating a new object.

32:44

How do you join a list of characters into a string?

easy Click to reveal answer

Use the join method on an empty string: ''.join(list).

33:41

What is the purpose of using random.randint in the 'very' strength?

medium Click to reveal answer

To generate a random number of digits (2-4) for the password, adding unpredictability.

34:54

What does the zip function do?

medium Click to reveal answer

It combines two or more sequences element-wise into tuples.

45:18

How do you unpack a zipped object?

medium Click to reveal answer

Use the splat (*) operator: new_students, new_grades = zip(*zipped).

46:43

What does the center() string method do?

easy Click to reveal answer

It returns a centered string of a specified width, padding with a given character (default space).

48:38

💡 Key Takeaways

💡

Pseudo-randomness explained

Clarifies that random numbers are not truly random, a fundamental concept in programming.

05:24
🔧

In-place vs return

Highlights a common pitfall with shuffle returning None, crucial for avoiding bugs.

07:35
⚖️

Incremental development

Emphasizes writing and testing small chunks to avoid debugging nightmares.

21:34
🔧

Joining a list into a string

Demonstrates a practical use of join to convert a shuffled list back to a string.

33:41
🔧

Zip and unpacking

Shows a powerful Python feature for combining and separating data structures.

44:19

[02:00] Oh, hey everybody. Let me check my mic. Test, test, test, test, test. Got that All right, just thought of something else. else. All right.

[02:16] All right, mute this. There we go. All right. Hey everybody, welcome back uh to Hey everybody, welcome back uh to another live stream. I am

[02:29] Sam from Python Basics and uh Beau and uh Beau and uh Quincy and everybody at freeCodeCamp allows me to come here every other week

[02:42] and do a stream and I'm super grateful for that and I'm always very excited. And we have quite a few people here today. So, us. Uh

[02:56] Uh we usually just do a stream from videos that I have done before on my channel and there is a link down below Um so if anytime there's anything you don't

[03:09] quite understand or if I've gone over, there are micro videos of everything we have done here and also this is Beau does a very good job. Uh all of these are cataloged on a playlist on freeCodeCamp's

[03:26] uh YouTube channel. Um after this, you can just click over there and check out. This is this is live stream 12, I believe. Uh Cardinal, you may correct me or not and we do have this is the 12th. There we go. Cardinal

[03:40] does an awesome job for us. He is our moderator, so he will keep us on task. Um and uh Cardinal, just FYI, I've done a better job. I got open, so there's anything you need to

[03:54] let me know that I will see specifically, just hit me up over there on our uh DM. Okay. So, there are a couple things. Nope, not the fourth or fifth. Uh uh

[04:08] Yes, there will be replayed. All right, I hope the background isn't too bad. I okay. Uh let's just go ahead and get started. want to cover uh first that you we

[04:25] may not be aware of. So, we're going to be doing a random password generator. Should have put that right there. Random random. random. And if you are new, you do not know yet

[04:39] that I cannot spell. So, you will see misspellings, typos, everything. So, that's don't don't uh don't be alarmed. You will probably catch um you will catch many typos. So, all right.

[04:55] So, in this password generator, what we're going to need from Python is of course something with uh random. And then, so we're not having to type in all of our uh letters and characters, we're going

[05:11] to use uh the string module. So, let's just go uh the string module. So, let's just go ahead and look as bring in random first. And put that into memory. And really learn learn about it. So,

[05:24] what in the world does random do? All right, der random. All right. All right, cool. All right. So, well, let's look at

[05:38] everything about it. So, it is a module that the core developers have already created for of for of us to random we're going to touch on towards the end and also stay tuned till the end cuz

[05:53] uh in under an hour and I have some extra going to sneak in at the end. So,

[06:06] if you haven't heard pseudo random, there is no real random. There just isn't because a human being will begin to uh repeat digits. There is actually that that is now

[06:21] There is actually that that is now noticed and then a computer is based on logic. So, these are actually called pseudo random and I have a thought and an idea to actually go over a little bit of how that is

[06:34] actually deduced, how a random number is actually calculated. So, but we need uh Um I think I just made that word up. Uh randomness and um then the actual characters that we're going to be using.

[06:50] So, what we're going to what we're going to use in our example is, let's get to the bottom, we're going to use choice. Let's see. So, help

[07:05] random choice. Choose a random element from a non-empty sequence. All right? That's pretty self-explanatory. Then we're going to use shuffle. So, we need to look at this

[07:19] use shuffle. So, we need to look at this and how how we use it. Shuffle. All right. was any. All right, so shuffle. This is super

[07:35] important. Uh and I like to really make a big deal about in place and return. So, shuffle does in place. It creates nothing. It doesn't return anything. So, and you're

[07:50] going to pass it the sequence, the list. list There we go. So, now now let's look at So, string is another module that the core developers have have created for

[08:06] us. And let's look at this before we get into it. Ah. All right. ASCII the characters that a computer knows,

[08:18] the characters that a computer knows, how it tabulates and keeps up with all key strokes. So, every character is a signed an ASCII variable. So,

[08:32] want to go over them right now. ASCII letters letters ASCII lowercase, ASCII uppercase ASCII digits ASCII punctuation. So, let's just jump

[08:46] at it. So, string So, string as and this is another one that I always have a hard time with. So, if we look really close, all right,

[08:58] you got Can you even use this in frame? This is in frame. All right, we have lowercase and uppercase.

[09:10] Lowercase and capital, excuse me, or uppercase. I don't know how All right, uppercase. I don't know how All right, so 52. So, 26 letters in the so 52. So, 26 letters in the English alphabet 26 Do we have lowercase

[09:22] and uppercase? So, that's 52. Now, letters is both lowercase and this out. string.

[09:34] as as key lower case And boom, I just get lower case. And And boom, I just get lower case. And then

[09:49] upper case. Boom, capital. All right. Oh, Jan's here. Awesome. Oh, Jan, please after after this um

[10:02] hit me up on Discord. I want to make sure we get you to be a uh moderator, Uh cuz you've been around a while. I think you sent me some stuff, but that was not Well, we'll we'll talk about that later. Uh glad to have you here.

[10:18] and glad to have We got quite a few people here today. So, glad we have uh questions. If they If I have gaps right now, please now, please please ask any questions because this is

[10:33] when you ask a question, somebody else has that same question, okay? So, ooh, I think I was shaking the camera. string digits All right. Oops. Uh what I do wrong?

[10:46] All right. Oops. Uh what I do wrong? string. dot Uh string Yes, uh is that what I did, Sting? Thank

[11:01] you. Good catch. Look, I I own what I can and what I cannot do. Uh typing I actually be I I I actually used to be a worse typer before um

[11:13] I began programming cuz you have to type these things right. Oops. Sorry, I thought I heard Discord.

[11:28] All right. All right. now that we have our base modules that we're going to be using, now we need to begin to create our

[11:43] So, would you guess what we're going to call this function? Uh we're going to call it Now, now we need to deal with some things

[11:56] now we need to deal with some things that we may or may not be aware of. So, we're going to be creating this function function with um

[12:10] So, we're going to need to take in arguments. Now, some of them are already a starting point. So, if you haven't heard the term

[12:22] default argument or optional argument, comment right now because we're going to get into it. So, if we need to go further into it, just let me know cuz let's just look at one of our highly

[12:35] used highly used functions right here, print. So, like I've done before, So, like I've done before, so these end perfect example, end is

[12:48] optional and it is defaulted to new line. That's what that means. So, when you have a So, I have to pass

[13:00] So, when I'm using uh sum, it is expecting iterable. It needs to have one argument. So, then if I pass

[13:12] So, right here, takes at least one positional argument, zero is given. So, we're going to set it up where we're going to have one one uh one positional and then two two optional, all right?

[13:27] So, let's just look and see what that is going to look like.

[13:39] uh how to replace um um methods with with lists. Okay. All right. So, what we're going to do is we're going to we're going to we're going to layer this password generator

[13:53] going to layer this password generator to uh let's see. We're going to have this hat be able to take digits and we're going to control the strength. We're going to have Let me get it up.

[14:09] Is it going to have digits and the strength of it? We're going to have three scenarios: weak, strong, and vary. Now, we need to pass this information on

[14:21] to the user. And And and how do we pass information on and how do we pass information on to the user of our function? We have to

[14:33] use a docstring. strength And we're going to set this up to true right now. All right. So, docstring. Anybody have

[14:47] All right. So, docstring. Anybody have any questions of what a docstring is? just this right here. This is the docstring,

[14:59] this right here. This is the docstring, documentation string. And this is with our three quotation marks. And

[15:13] we're going to tell the user what information they need to know. what information they need to know. So, length of password

[15:34] if you want a number want a number and then

[15:49] weak And I moved my camera, so if I am moved my light so I would get rid of shadows. So if I'm squinting a little that is why. So all right. Length of password

[16:05] num if you want a number and strength weak, strong, and very. weak, strong, and very. So that is what is going to happen if we then call password.

[16:19] So now I have my documentation string right there. Boom. Let's do this again. in straight frame. Shoot, is it? Yeah, sorry guys. All right. Up, let's move this up just a

[16:33] touch cuz I had a multi multi-line. There we go. Boom, there we go. So whatever you type information that's passed along when you begin. So then the user understands and

[16:48] you can communicate even more in depth and then of course uh when you can even have even more, but we'll deal with that at a later time. All right. So

[17:03] anything before we move on to the actual structure of the function? Anything good Jen? before before on that I might have missed.

[17:18] Is that light too bright? Do I look all washed out? All right, so now we just need to jump at it.

[17:30] at it. All right, where are the notes? All right, where are the notes? I need to get that ready. So we don't need pass anymore. So now we have

[17:46] So now we need to begin to account for our scenarios. So we're going to have So we're going to take length. Then we're going to have weak, strong, and vary. So we need to account

[17:59] for We'll deal with num in a minute. but right now we need to have three scenarios.

[18:14] Thank you. Misspelled strength. Let's see, did I do it right that time? Is it getting back Is it getting closer?

[18:37] Thank you, Cardo. I don't know exactly what you deleted, but awesome. Okay. All right, so we going to need an if.

[18:54] first. So we need to start separating these. So So we need to start separating these. So we're going to have string lower, and we're going to have upper

[19:10] cuz we want to we want to differentiate between these and we're going to have there. as key as key upper

[19:24] Now, let's do digits. And we know that's Okay, 1 2 this?" Well, we I want to just have some

[19:39] consistency here. So, I'm going to do lower and it's less typing. plus Whoa.

[19:56] upper And digits. string. And then punctuation. punct

[20:08] punct string. punct I always I didn't know I misspelled this. I don't think I'd actually ever punctuation. And then our password, we're going to

[20:21] increment this. So, we're going to start out with a empty string. out with a empty string. All right, any

[20:41] this stream and also basically over on my channel is my channel is if somebody is beginning to watch this if somebody is beginning to watch this and has zero experience with programming

[20:53] and especially Python that um you can jump in, follow along, and it can make sense. We keep this as basic as possible and try to move very

[21:05] slowly into advanced areas. So, I hope that answers a couple of the questions that I just kind of saw. All right. Cuz there cuz programming can All right. Cuz there cuz programming can get very overwhelming very very quickly.

[21:18] get very overwhelming very very quickly. If strength weak. All right. Pass. All right. So, now I have So, I'm going to default this to weak.

[21:34] So, now So, as you go through and as you change one thing change Don't don't write this whole thing at one time and then try to run it cuz you're going to make a mistake. I don't know if you if you've

[21:48] been over to my channel and seen the um seen the video on incremental development. Write write one functionality, test it. Because you could have it fail You you could write uh you could write a whole section and

[22:04] it begins failing all over the place and you have no idea where to start. So, write one thing to change, test it, move on. Because when you go back and you start changing one or two and the whole thing just fails, you just want to rip

[22:18] your eyeballs out. So, all right. Let's just incr incremental incremental incremental. Incremental improvement, incremental change. All right. So, there There's my little There's my little soapbox for today.

[22:31] All right. So, we have this now. This is how we're going to handle uh Excuse me. I've been a little congested recently.

[22:47] All right. So, actually, let's build on this. So, So, actually, let's build on this. So, for we won't do the numbers yet. for we won't do the numbers yet. So, for I in

[23:01] So, for I in range length.

[23:18] Then I'm going to take my password and I'm going to increment it up with my random choice from lower. Actually, I just thought about it. We

[23:30] didn't actually No, we we did look at choice, right? Yeah, okay. It's going to randomly pick. So, I'm going to randomly pick from lower. So, right now weak is just dealing with the lower case letters and

[23:44] that's it. So, if I pass it and we already have it set on weak, so and we already have it set on weak, so if I do password and I pass it five. Uh I don't have it printing out

[23:57] anything. Print password. Actually, Actually, this needs to be return PWD.

[24:17] is then password five. There we go. So, of course, it's going to be random

[24:32] again. So, just just like so. So, now I have a five-letter password, but they're all lowercase. So, that scenario is again pretty weak.

[24:45] So, now let's add Well, what happens if we want some numbers? So, now let's add we want some numbers? So, now let's add some functionality that if num

[25:00] if num and length then for I in range

[25:14] for I in range two

[25:27] random choice move on. So, all right. Now, let's go over this.

[25:44] So, now I just hardwired this. So, if false So, it's defaults to false. So, it's not going to include a number unless you change it to true. Then, if this is

[25:57] true, because this is So, now, if I go

[26:09] num equals true So, now, when this catches true this is going to reduce. So, we're we're we're defaulting and hardwiring this

[26:23] into I want at least two of my I want at least two of my two of my characters to be digits. So, I'm removing this down, making this shorter by two.

[26:36] Then, I'm going through here two times, grabbing two digits, then continuing on. So, now, let's run this. let's run this. So, now, let's run this again.

[26:49] we're going to we'll deal with this later with some randomality randomness. Should have probably looked that up before I started to be able to conjugate randomness. So, I'm going to have two random numbers

[27:05] So, I'm going to have two random numbers at the beginning and then the remainder at the beginning and then the remainder of them will be characters. So, now that our weak. So, now let's do something with strong

[27:20] and we'll deal with this in a minute. So, I had my if, that's my first condition and then L if

[27:33] strength equals

[27:47] to then include both uppercase and lowercase in strong. both uppercase and lowercase in strong. And then for uh with very, we're going to add punctuality,

[28:02] too. Punctuation, not punctuality. I knew that sounded weird. Sorry. We're going to add punctuation to to our random to add punctuation to to our random password.

[28:17] Okay. So, now So, now we saw what we did with numbers, So, now we saw what we did with numbers, so we're going to do num if and let's see what we did. We're going to go So, now with

[28:30] strong, we're going to keep this as two and then with very, we're going to add a little bit of uh flexibility and a little bit more randomness. So, that's why we're not

[28:44] over we're not blanketing our number choices, and then we want them to be choices, and then we want them to be very they we want them to vary each each So, all right. Let's see. So, we got Let me just get

[28:57] where I see where I am with my notes. We're on strong. We're on strong. So, same thing. We're going to lengthen by two.

[29:11] two. And then four

[29:24] increment I can increment. My typing's not that great today, everybody, so I apologize. Uh then our random choice random choice

[29:45] And then we'll come out here and still do our passwords. But now this for I in range length

[29:57] Now, here's where it's going to change, where we're giving a little bit more depth of character. We're going to use We're going to use choice.letters.

[30:14] actually All right. So, and since I already this, so we'll leave letter and letter the same. So, now we have upper and lower case here. Let me check my indentation. Something didn't feel

[30:27] right. All right. So, now we'll leave that. Copy, paste. And then And then now we're going to have

[30:47] strong. All right, does everybody understand All right, does everybody understand what I'm doing so far?

[31:17] So, now I have my strong and I have five here. Let Let's up this to 10.

[31:30] So, now I have up I have digits, capital and lowercase all in together. But, as you'll know, we have a problem here where

[31:42] somebody starts seeing this, they're going to realize, "All right, so I only have to pick There's only digits at the front, so we need to we need to handle this right now." So, random

[31:56] So, random .shuffle in a minute. So, wait a second. Shuffle a list. Hmm.

[32:10] So, that's a problem. So, we need to come here and go password list password. We need to turn this into a password. We need to turn this into a list.

[32:28] Aha! What is our issue? What, to remind you, is this is what so help What did random What did random uh shuffle do?

[32:44] Who remembers in the doc string? random.random.shuffle It's a very big issue that you have to pay attention to when you're reading the documentation. This is it right here.

[32:59] in place return none So, it doesn't create anything. So, when I pass this, it returns none. That's why I get none right here. So, I need to then

[33:12] put this back. I need to So, I run that. And And return

[33:27] Ah, one more problem. This is still a list. So, now I have to Uh do do do do. So, this is this is a list. We got I got a ha ha ha dot

[33:41] join password Bam. So, now I have shuffled rejoined I'm using my join method on on a list

[33:56] for a string, and now I have these random passwords. So, we have weak, we have strong. Now, let's go ahead and knock out

[34:09] Uh we do we've We've handled a lot of this. So, now let's go

[34:23] now let's go All right. I'm going to type that pretty good. equals very

[34:38] very strong, right? So, we need to add a little bit more some some randomness to this. ran equals random

[34:54] equals random .randint I don't even know how many digits it's going to have. It's

[35:06] going to have two, three, or four. So, I wanted to make this a little bit even even even more more out of my hands. Okay?

[35:27] Now, we need to do some a little bit of math we here just like we did with our two, but now we need to handle we need to handle this. So, we got Let me see where I am with my notes.

[35:39] All right. So, do do do do do do and also to let everybody know that I've gotten pretty good at not closing out the shell and after this closing out the shell and after this stream going over to my uh GitHub. So,

[35:54] stream going over to my uh GitHub. So, you can get to my GitHub on any video you can get to my GitHub on any video link link on my uh YouTube channel. And all of this is there. I have one one full consistent uh free code camp.py

[36:10] file that I keep adding to and then the notes, the shell, all the notes, all the output for the day that I have in a file dated uh today and that's in its own uh folder uh free code camp folder over on my uh uh, GitHub server on my repository

[36:28] just to let everybody know I have not been voicing that as much as I've been meaning to. So, all right. Where are we? So, we are we're at our if num then we need to adjust this a little

[36:43] So, now all these others were just at de- decrementing down by two. Well, we need to set up some functionality. We don't know how many digits it's going to have. We know

[36:58] with an idea with a random number. So, now we need to increment down by that. And then, oops. And then, oops. Then, for I in range of ran

[37:15] Then, password and increment and increment up by random choice digit

[37:28] and then I come out. So, then I need to shorten the length by my ran incrementation. incrementation. Then, for I in range ran

[37:47] uh punctuality, too. We're going to use that same that same uh that same that same uh for this right here.

[38:04] Password increment random random dot choice dot choice punct

[38:18] some letters. For I in range whatever is left over. have typically a very long password. random dot and then you could set some

[38:32] function functionality up. Be like, "Hey, and letter letter letter." "Hey, and letter letter letter." All right.

[38:44] there. Boom boom boom. Boom boom boom. Damn. All right. Let's clean that up some. So, now

[38:59] copy. Let's go 15. And I we have vary. Let's see how we did. Check the any good Let's see how we did. Check the any good comments.

[39:12] Do you know that people actually That's like the most used I think there's a list. There was an old movie. Well, I say old. Ancient to you guys, old to me. Um it was called I think Hackers back in like

[39:25] was called I think Hackers back in like '90 1993 or 1994. people in it that hadn't been seen yet before.

[39:37] before. So, all right. All right, so here we go. Whoa. Let's see where I got what I left out.

[39:53] And ah whoa. Well, that's not good. Let's see, I left a whole bunch of stuff out. stuff out. length letter choice

[40:10] And then uh increment up. random dot choice

[40:23] eyes are all over the place today, everybody. I apologize. Length. Dot. Parentheses letter.

[40:38] There we go. Okay. right. It had It did have Angelina Jolie and a couple couple

[40:51] couple of others. It was a very interesting movie. Okay, It was a very interesting movie. Okay, now check this out. Oh, good question. All right, so let's break let's break this out. So, what

[41:05] break let's break this out. So, what does what does this do right here? All right, help. Dot.

[41:17] String. Dot. Join. Uh do do do do do do. Help. Dot.

[41:30] str. Dot. Join. My fingers are not typing. Okay. Join. My fingers are not typing. Okay. So, this is a little odd and you might any sense." Because you're passing it a list, but

[41:45] you're getting a string. Most of the time you have a string and then you do something to it. So, let me let me see if I can So, you're having a string that you're saying, "Hey, I don't want any spaces in

[42:00] it." And this is the This is the list or the sequence that I want to put with this string that doesn't have anything in it. So, if I were to I know that sounds really weird. So, let's look at this right here. So, I

[42:15] have a list of uh name. I got Sam. Then I take name and I throw it in a name So, now I have name and it's a list,

[42:28] right? So, now I want you to make a string have zero spaces in it. And I want that information for you to put in there with no with no space is the list with the

[42:44] contents of that the contents of name. Now, and I can do I can put anything in there. I want a space, so then I do join.

[42:57] I get which happened to be the characters of my name with a space in between. Now, this is where it gets really handy. I want to put an asterisk between

[43:12] all of the characters. Which happened to be my name. And again, it's whatever string you want. It's a It's a uh want. It's a It's a uh It's a reverse split. Think about that.

[43:34] contents of a sequence. And then whatever Here's the glue. Cuz I remember the first time I was like, "Well, why isn't join a

[43:46] list method?" Well, it's not because you're using this string, then that's a string, and then this is the method for this string with this sequence. There we go. All right. Really good question.

[44:04] Uh let's see. Let's see. Let's see. All right, cool. I was hoping we would get And um I did not mute the tablet. Hope that isn't too too disturbing. So, I actually

[44:19] wanted to go over we're going to do a little bit of bonus stuff. little bit of bonus stuff. Um so, let's go over some things that Um so, let's go over some things that just are random that I've had on my

[44:31] channel that um Actually, let me make sure that this is everything that I wanted to All right. Yes, let me check these notes right

[44:47] Yes, let me check these notes right here. seen um packing packing and unpacking. Well, I want to show you

[45:02] this. Let's comment that out. So, I want to show you how to unpack with a splat and zip. So, with a splat and zip. So, let me just show you this.

[45:18] So, we have we have two lists. We have student We have student we have grade the grade that they're in. And we want to put them together. So, I want to zip them together.

[45:41] So, I'm going to zip just like a zipper. You put one side to the other. So, I'm going to zip these together. Student and grade.

[46:01] with tuples with and it zips it one after another. So, that is a very handy tool. that is a very handy tool. But,

[46:14] now what happens if I wanted to unpack this? How would I go through? I could go this? How would I go through? I could go in and I could go and really

[46:26] where how it's like I could I could chop this up? Well, I remember when I first this up? Well, I remember when I first saw this, this was the coolest thing. So, new student

[46:43] So, now I can literally use the same tool, but I can literally use the same tool, but I'm going to use a splat character.

[46:58] So, I'm going to pass this back through and this is how you literally unzip. and this is how you literally unzip. So, now I just unzipped

[47:10] everything. So, now I have new students I remember that was so I have grade and grades, so I just didn't type the same.

[47:23] Now, all right. So, that's that's bonus one. And I was looking through the other day and I haven't done a very good job of

[47:35] showing you guys cuz it's basically kind of like the question of, "Hey, what in of like the question of, "Hey, what in the world does that join do?" because you've never talked about it. So, now let's let's kind of look at some string

[47:47] let's let's kind of look at some string stuff right here. All right, that's not the one I I to see. I wanted to see this. All right.

[47:59] see. I wanted to see this. All right. Okay. Help. All right. Put that in the memory. X

[48:13] All right. Put that in the memory. X and dir on X. and dir on X. I have all of these methods right here. Check this one out. I remember the first time I was sitting this trying to solve

[48:25] this problem and it was a just a silly thing to make to to to make you think Help. Nope. Center. We're already pulling that up. Help. Okay. Ah. Return a centered string of a

[48:38] Okay. So if I pass in center and if I give what?

[48:53] What does it do? Is it in place or does it return? It returns. So we got one of two ways. So X.center

[49:05] center equals and then what do I want to have around it? Let's do Let's do So now check this out. So this is 50 characters and help is in the center.

[49:22] Okay. That was one of the cool cool ones that I liked. Um let's see. And we'll go we'll go over more. Oh, well that's not what I wanted to do. Oh, yeah. Sorry.

[49:34] over here. All right. So now here's another one that I like a lot. Okay.

[49:50] Okay. Comment this out. Comment this out. So, now I have a list of names and digits. Integers.

[50:09] help dot uh dir dot str. Uh a i is uh what am I looking for?

[50:23] Uh a i is uh what am I looking for? Is upper, is title, is digit, is uh is space.

[50:37] Which one am I looking for? Is numeric. That's what I wanted. Is Is numeric. That's what I wanted. Is ASCII, is numeric. So, I want to create a list of

[50:50] name equals We're going to do some list comprehension here. False. If str

[51:07] meric, else for for i in x.

[51:25] Run this. Name. So, now I go through I go through and what I just did is I took We We We

[51:38] do for i in x i in x print i, right? at because this was a string

[51:53] and it went through and I wanted to know the reason why I did it like this is because it knows if this is a it knows if this is a right here integer integer but still

[52:07] right here integer integer but still that is an integer just an as key integer or numeric. So, that was that. Now, I cannot remember if we have looked at the helped the help

[52:21] prompt on on any of these streams. Jan uh Cardinal, do you guys remember if we have done the help prompt because I'm sure with out of out of these 400 so

[52:36] there are some people that

[52:49] when you don't pass in an argument for help you get the help prompt. And this is where Python becomes extremely powerful.

[53:04] So, you can literally cuz this was kind of like Okay. So, then uh okay. So, then you start bouncing around and then you have

[53:22] up functions functions and then uh what am I thinking about? Oh. Keywords words. There we go.

[53:35] Keywords words. There we go. Oh. Okay. So, if you've noticed that Oh. Okay. So, if you've noticed that there's no way for you to run help on some things cuz you can run help on a function and on a method, right?

[53:54] Then, let's see. What does four do? Oh. So, there is a lot of documentation on four. Okay, so it goes through and it So, you don't have to This is Don't try to memorize anything. Understand

[54:08] what you want to do. So, I hint. Okay, so then we're talking about range. Okay, so So, now now you're going down this rabbit hole. So, what is four? Okay, and it has a scenario range. Well,

[54:20] Okay. And then I got 83 lines of range. Okay, that that is the function. Okay, so that is that is the function that has the stop or the three arguments. So,

[54:35] here's the two Here's the optionals. And we just go from there and you end up going down this rabbit hole. Keywords. Okay, so what is this What is this while?

[54:56] What it What is What then I'm just bouncing around. None. What is none? And don't Don't confuse Don't confuse this cuz that's not anything. Aha.

[55:11] Aha. So, it's a none none none type. So, there we go, guys. That is I was really hoping I'd get to all of these things, but this is a super important feature. In fact,

[55:27] that if you have a question and you can't get it answered anywhere jump over to my channel drop it in one of the comments. Hit up any one of us on Discord and you're not

[55:43] in this you're not in this alone. All right? I believe in everything that Code Camp is doing, what Quincy's trying to do, what Beau run Uh we are all to help you here in your

[55:56] Python journey. And the reason why I make the micro videos is because I remember the journey that I was on trying to learn programming and I was all over the place. I'd see a video, I'd do a video,

[56:11] I would try to remember where I saw it. Every single topic that I've covered here so far is in a micro video over on my channel. You're not going through this alone. All right? So, I just wanted to say that.

[56:25] If you're spending time doing this, you're doing a very good job. All right? And Free Code Camp is here. Uh I'm here. You're not You're not be able just sit down, type

[56:42] little bit of the time. Don't try to solve the whole problem at So, all right, guys. There we go. Another great stream. Uh you guys are doing awesome. Uh I want to appreciate Free Code Camp. Make sure

[56:56] you're uh subscribing to their channel as well. Uh join in if you can. Buy as well. Uh join in if you can. Buy buying any merch. Um great organization. Wholeheartedly believe in everything that they are trying to do. So, there we

[57:08] go, guys. Uh another awesome stream today. today. Um and we will see you guys in 2 weeks. Um and we will see you guys in 2 weeks. Thanks, everybody.

More from freeCodeCamp.org

View all

⚡ Saved you 0h 57m reading this? Transcribe any YouTube video for free — no signup needed.