Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences 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 refer to our video player troubleshooting guide for assistance.

Exploring Special Function Parameters (Overview)

Have you ever come across the forward slash (/) and asterisk (*) symbols in the documentation for your favorite libraries? These represent special parameters, which tell you what kinds of arguments you can use to call a given function. In Python, these parameters can help you ensure that your functions are used correctly.

Maybe you’re a regular at Real Python’s weekly Office Hours meetup, or perhaps you’re curious about what happens there. You’ll get a glimpse in this Code Conversation, which answers one participant’s question of how to interpret and apply special function parameters in writing and calling functions.

In this Code Conversation video course, you’ll learn how to:

  • Set default values for arguments
  • Write positional-only, keyword-only, and combined functions
  • Refer to the forward slash (/) and asterisk (*) accurately
  • Use special function parameters in real-world code
Download

Sample Code (.zip)

270 bytes

00:00 Welcome to today’s Code Conversation. I’m Ian Currie, a Real Python team member, and I’m going to be having a conversation with Martin Breuss, who’s another Real Python team member. Hi, everyone.

00:12 Every week for our subscribers, we hold an informal hangout session that we call Office Hours. In these sessions, we hop on a video call and chat about anything Python or programming related.

00:24 Recently, a subscriber was asking about some strange function parameters that they noticed. While chatting about it, we all learned something, and we thought it would be a great topic to discuss in a Code Conversation. So in this conversation, Martin and I will be exploring special function parameters.

00:43 Martin and I will be chatting in a VS Code Live Share session, so sometimes you’ll be able to see Martin’s cursor jump around the screen to highlight something.

00:53 The special function parameters are the forward slash (/) and asterisk (*). These allow you to control how you want the function to be used.

01:02 Specifically, it allows you to define what parameters should be called as positional-only arguments, keyword-only arguments, or a mix of both. Now before jumping in, we’re going to disambiguate some terminology.

01:17 The function on-screen now is called hello(). It’s a function that is defined with one parameter, called name. This function takes the name and then prints "Hello, {name}".

01:28 So if the function is called with an argument of "Pythonista", for example, the expected output would be Hello, Pythonista. Now, did you notice the terminology I used for defining the function and using the function? Technically speaking, when you define the function, you define parameters, and then when you call a function, you call it with arguments. In this case, you define hello() with a parameter of name, and then when you call it, you call it with an argument of "Pythonista". However, in informal conversation, it’s common to hear the terms parameter and argument used interchangeably, probably leaning towards using just argument for both cases.

02:16 With that, it’s time to get stuck into special function parameters.

Become a Member to join the conversation.