This lesson provides an overview of the powerful and flexible Python string formatting methods. Both literal and variable strings may be formatted.
- [Narrator] Python has rich string formatting capabilities.…Here in Komodo, I've opened a working copy…of Hello.py from chapter 11 of the exercise files.…Python 3 uses a string method, called format,…to format strings, and it works like this.…If I create a variable, X equals 42,…and here in the string I can say,…"The number is,"…and I use these curly braces for a placeholder,…and I type format,…and give format the variable X,…and when I run it, you'll notice it says,…"The number is 42."…So, in some languages, they call this string interpolation,…but here, the method of the madness…is exposed by allowing us to use…the format method, like that.…
The curly brackets are a placeholder,…and the format method specifies values for the placeholder.…If you have multiple values,…say Y is 73, and I want to…give another number here,…I can specify the second value in format with a comma,…and when I run it, you see it displays both numbers.…You can name your variables, like this,…xx, and bb,…and then in the format,…you can say xx equals, and bb equals.…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- 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.