Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Looking Ahead to Python 3.14: T-Strings & REPL improvements

More at Real Python

In this course, you’ve learned:

  • Key new features introduced in every major Python version, starting from early Python 1 up through Python 3.14
  • The story behind pivotal changes, like list comprehensions, exception handling, the with statement, defaultdict, and the transition from Python 2 to Python 3
  • Hands-on use of modern Python tools: f-strings, dataclasses, the walrus operator (:=), match/case structural pattern matching, and new types like enum and pathlib
  • How to leverage improvements in each Python release for cleaner, faster, and more maintainable code
  • What’s coming in the latest Python releases, including t-strings and REPL improvements
Download

Course Slides (.pdf)

1.5 MB

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 Previous lesson covered the performance improvements in Python 3.12 and 3.13. This lesson gives a little preview of Python 3.14 and shows you t-strings and some of the REPL improvements from both 3.13 and 3.14.

00:16 We recorded this course in the summer of 2025 and Python 3.14 isn’t out yet, but it’s in the release candidate stage. The target for the release is October.

00:25 Typically it’s in the first week or two. One of the big changes here is the continued work on the GIL-ectomy with the free-threaded mode being included as fully supported rather than as an experiment as it was in 3.13.

00:39 It’s still optional and requires a flag to use, but progress is being made. Language-wise, the big new feature is t-strings. These have the same format as f-strings, but instead of returning a string, they return a template object containing the constituent parts of the string being parsed.

00:55 This can be helpful when writing libraries and dealing with things like user input escaping. The other nice thing in this release is even more improvements to the REPL.

01:05 It adds syntax highlighting to go along with the improvements from before. Let’s head into that new REPL and play with those t-strings.

01:15 I’m a traditionalist, so let’s start with “Hello, World!”

01:21 Aren’t the colors pretty? Alright, a little more code.

01:32 And here you see not only the pretty code highlighting, but some of that error message improvement discussed earlier. Little caret symbols highlight exactly which word is problematic, and the error message even suggests what might be the correct value.

01:46 Let’s do it right this time. In the older versions of the REPL, I would have to hit up arrow for each line in this for loop, but now the REPL treats them as an editable block.

01:56 So when I hit the up arrow, I can edit the error.

02:02 There you go. Much better. Python 3.13 also added a history feature, which of course is there in 3.14 as well. When I hit F2, you see all the things I’ve put in the REPL in the past.

02:14 Unfortunately, it’s sorted in chronological order, so you have to go all the way to the bottom

02:27 in order to get the stuff that you’re actually after. But once you’re here, I can copy the code, then hit F3 for paste mode,

02:41 and this allows me to easily copy and paste blocks of code into the REPL, a long overdue feature that was common in many of the third-party REPLs. Okay, how about that t-strings thing?

02:53 Let me define a variable and now I’ll write a t-string. It looks just like an f-string, but with a T prefix instead.

03:06 And as you can see, the result isn’t a string, it’s a template object. Let me do that again. This time, putting the result in a variable.

03:18 The attributes on a template object tell you about the contents of the t-string. Strings are the string portions. Notice the empty string there denoting that nothing comes after the amount field.

03:31 There is also the .values attribute containing the interpolated values for each field.

03:37 Or if you need more details, the interpolations tuple contains an interpolation object for each field, which itself contains the resulting value, name of the field, some information about whether this was generated with __repr__ or __str__(), which is None by default.

03:53 And finally, on the end there, the format specifier, if there was any. T-strings are going to be useful when dealing with user input as it allows an f-string-like syntax, but gives the library coder a chance to look at the contents and do something like escape out bad content before finally doing something with it.

04:09 One of the things that people were excited about this is this idea of having it be able to avoid some potential pitfalls that maybe could happen with an f-string, that being like a SQL injection attack.

04:23 Or the other thing that’s kind of nice is if you’re doing like a logging environment, you can do sort of a human-readable version and JSON version of it at the same time, because these are returning this object with all the different components you can kind of reconfigure.

04:38 And then initially they seem like there’s a lot of stuff being returned, but I think what you mentioned in this course that we’re going to talk about is that there could be higher-level libraries that would be built on top of this.

04:51 It’ll be interesting to see how people build on top of this in later versions of Python and other libraries.

04:58 And although Python 3.14 is still new, there is content on the t-strings that I just demonstrated for you in both tutorial and course format if you’re interested.

05:09 Well, Mr. Bailey, thanks for joining me on this little journey. Yeah, it’s fun to do a code conversation with you. Thanks for your attention. I hope you enjoyed the course.

Become a Member to join the conversation.