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

Unlock This Lesson

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

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Write and Test a Python Function: Interview Practice (Summary)

Now you’re ready to tackle your own coding challenges and wow your interviewers! In this Real Python Code Conversation, Philipp challenged Martin to write a function that doubles each character in a string. Through their conversation, you learned how to write solid code and talk through your process as you do it.

In this video course, you learned how to:

  • Use functions to write reusable, maintainable code
  • Communicate your thoughts in a coding interview
  • Use if __name__ == "__main__" to build multipurpose code
  • Write tests and use test-driven development

If you want to learn more about the concepts that you explored in this course, then you can check out:

Download

Sample Code (.zip)

821 bytes

Download

Course Slides (.pdf)

13.1 MB

00:00 In this Code Conversation, I gave Martin a coding challenge. His task was to create a function that doubles characters. It was neat to see the code that Martin came up with, but even more interesting to me was the conversation we had about the code.

00:16 While he was solving the challenge, we talked about tackling coding challenges, how to communicate during a coding interview, how to improve your code with functions, importing modules, and creating tests.

00:30 I want to wrap up this code conversation with links to additional resources. In the next slides, you’ll see two icons for tutorials and videos next to the links.

00:40 When you download the PDF with the slides, you can click the icons, and it will lead you to the tutorial or the video if there is a course attached to the tutorial.

00:51 Here are some resources if you want to prepare for coding interviews. In “Python Practice Problems: Get Ready for Your Next Interview,” you’ll prepare for future interviews by working through a set of Python practice problems that commonly appear in coding tests.

01:07 You’ll work through the problem yourself and then compare your results with solutions developed by the Real Python team.

01:14 In “How to Stand Out in a Python Coding Interview,” you’ll learn how to take your Python coding interview skills to the next level. This tutorial is focused on Python’s built-in functions and modules to solve problems.

01:28 That’s an important skill because usually you can’t install external libraries during an interview. If you want to try out fun coding challenges, then Advent of Code is just for you.

01:38 Advent of Code is an online advent calendar that shares new programming puzzles each day from December the first to the twenty-fifth every year. The cool thing is you can access the coding challenges from the last years anytime now. In “Advent of Code: Solving Your Puzzles With Python,” you’ll learn why solving programming puzzles can be beneficial and how you can get started with Advent of Code using Python.

02:05 In this code conversation, we also talked about why functions are a good idea. If you want to learn more about them, then these three resources are for you. “Defining Your Own Python Function”: in this tutorial, you’ll learn how to define and call your own Python function.

02:21 You’ll also learn about passing data into your function and returning data from your function back to its calling environment. In “Python Scope & the LEGB Rule: Resolving Names in Your Code,” you’ll learn what scopes are, how they work, and how to use them effectively to avoid name collision in your code. Additionally, you’ll learn how to take advantage of a Python scope to write more maintainable and less buggy code. The concept of scope rules how variables and names are looked up in your code.

02:55 The letters in the acronym LEGB stand for Local and Closing Global and Built-in scopes. This summarizes not only the Python scope levels, but also the sequence of steps that Python follows when resolving names in a program. In “Using Python Optional Arguments When Defining Functions,” you learn about optional arguments and how to define functions with default values.

03:21 You’ll also learn how to create functions that accept any number of arguments using *args and **kwargs.

03:29 Next, import and modules. Just like functions, modules and packages are all constructs in Python that promote code modularization. The tutorial “Python Modules and Packages - An Introduction” explores modules and Python packages, two mechanisms that facilitate modular programming.

03:48 Modular programming refers to the process of breaking a large, unwieldy programming task into separate smaller and more manageable subtests or modules. In “Defining Main Functions in Python,” you’ll learn how Python main functions are used.

04:04 You’ll also learn some best practices to organize your code so it can be executed as a script and imported from another module. Speaking of import, the Python import system is as powerful as it’s useful. In “Python import: Advanced Techniques and Tips,” you’ll learn how to harness this power to improve the structure and maintainability of your code.

04:27 The tutorial provides a thorough overview of Python’s import statement and how it works. Last but not least, testing. Hopefully Martin and I sparked your interest to use tests in the future.

04:40 If you want to get started with testing, then “Getting Started With Testing in Python” is, well, a good start. In this tutorial, you’ll learn how to create a basic test, execute it, and find the bugs before your users do.

04:53 You’ll learn about the tools available to write and execute tests, check your application’s performance, and even look for security issues. While this tutorial focuses on the built-in unittest library, there is another library that’s often used for testing called Pytest.

05:11 So once you have understood the basics, then “Effective Python Testing With Pytest” is a good next read. In this tutorial, you’ll learn how to take your testing to the next level with Pytest. You’ll cover intermediate and advanced Pytest features, such as fixtures, marks, parameters, and plug-ins. With Pytest, you can make your test suites fast, effective, and less painful to maintain.

05:37 If you want to learn about a new topic while trying our test-driven development, then “Build a Hash Table in Python With TDD” is for you. In this step-by-step tutorial, you’ll implement the classic hash table data structure using Python. Along the way, you’ll learn how to cope with various challenges, such as hash code collisions, while practicing test-driven development—in short, TDD.

06:03 I hope these resources will keep you busy while we continue to produce more Python tutorials for you. Thanks for watching this episode of Real Python: Code Conversations.

06:13 My name is Philipp. See you next time.

Become a Member to join the conversation.