In this video, Kathryn teaches you how to use the built-in len() function to calculate a given input's length.
- [Presenter] Let's figure out how to use the len function.…Len takes one input, a list, and it outputs…a whole number representing the length of that list.…Lists can take many different formats.…Let's consider strings to start.…So say we have a variable called first name,…and we'll make the first name be Taylor, have that value.…And then we'll go ahead and use the len function,…and we'll do a print statement,…and we'll say len first name.…And this will give us the length of the first name.…And for strings, length means the number of characters.…
Here we get six, because Taylor has six characters in it.…We can also use this for the last name,…and so we'll say last name equals Swift.…Then we'll go print len,…again printing out the length of the last name here.…And Swift has five characters,…and that's why we get five characters in the output.…And so why does this work for strings?…Well strings have a special property.…We go first name dot len.…We see that it has the length property,…and so because it has the length property,…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
Learning the Standard PHP Librarywith David Powers3h 24m Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.