Register for our webinar

How to Nail your next Technical Interview

1 hour
Loading...
1
Enter details
2
Select webinar slot
*Invalid Name
*Invalid Name
By sharing your contact details, you agree to our privacy policy.
Step 1
Step 2
Congratulations!
You have registered for our webinar
check-mark
Oops! Something went wrong while submitting the form.
1
Enter details
2
Select webinar slot
*All webinar slots are in the Asia/Kolkata timezone
Step 1
Step 2
check-mark
Confirmed
You are scheduled with Interview Kickstart.
Redirecting...
Oops! Something went wrong while submitting the form.
close-icon
Iks white logo

You may be missing out on a 66.5% salary hike*

Nick Camilleri

Head of Career Skills Development & Coaching
*Based on past data of successful IK students
Iks white logo
Help us know you better!

How many years of coding experience do you have?

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Iks white logo

FREE course on 'Sorting Algorithms' by Omkar Deshpande (Stanford PhD, Head of Curriculum, IK)

Thank you! Please check your inbox for the course details.
Oops! Something went wrong while submitting the form.
Our June 2021 cohorts are filling up quickly. Join our free webinar to Uplevel your career
close
closeAbout usWhy usInstructorsReviewsCostFAQContactBlogRegister for Webinar

args and kwargs in Python

Last updated by on Aug 30, 2024 at 09:30 PM | Reading time:

The fast well prepared banner

Attend our Free Webinar on How to Nail Your Next Technical Interview

WEBINAR +LIVE Q&A

How To Nail Your Next Tech Interview



args and kwargs in Python
Hosted By
Ryan Valles
Founder, Interview Kickstart
strategy
Our tried & tested strategy for cracking interviews
prepare list
How FAANG hiring process works
hiring process
The 4 areas you must prepare for
hiring managers
How you can accelerate your learnings
Last updated on: 
August 31, 2024
Author

Attend our Free Webinar on How to Nail Your Next Technical Interview

Register for our webinar

How to Nail your next Technical Interview

1
Enter details
2
Select webinar slot
First Name Required*
Last Name Required*
By sharing your contact details, you agree to our privacy policy.
Step 1
Step 2
Congratulations!
You have registered for our webinar
check-mark
Oops! Something went wrong while submitting the form.
1
Enter details
2
Select webinar slot
Step 1
Step 2
check-mark
Confirmed
You are scheduled with Interview Kickstart.
Redirecting...
Oops! Something went wrong while submitting the form.

args and kwargs in Python

# What are args and kwargs in Python? Args and kwargs are two parameters used for writing functions in Python. Args stands for arguments, and kwargs stands for keyword arguments. Args are used to pass a non-keyworded, variable-length argument list to a function. Kwargs allow you to pass keyworded, variable-length argument list to a function. In brief, args and kwargs are used to pass a variable number of arguments to a function. ## What are Args? Args are used to pass a non-keyworded, variable-length argument list to a function. This means that you can pass as many arguments as you want to a function, and they will all be stored in a tuple. For example, if you had a function that added two numbers together, you could do this: ``` def add_numbers(*args): total = 0 for a in args: total += a return total print(add_numbers(1,2,3,4)) ``` The output of this code would be 10. The *args allows you to pass in as many numbers as you want, and they will all be added together. ## What are Kwargs? Kwargs are used to pass keyworded, variable-length argument list to a function. This means that you can pass keyworded arguments, and they will all be stored in a dictionary. For example, if you had a function that printed out the details of a person, you could do this: ``` def print_details(**kwargs): for key, value in kwargs.items(): print(f"{key}: {value}") print_details(name="John", age=25, city="New York") ``` The output of this code would be: ``` name: John age: 25 city: New York ``` The **kwargs allows you to pass in as many arguments as you want, and they will all be printed out. In conclusion, args and kwargs are two parameters used for writing functions in Python that allow you to pass a variable number of arguments to a function. Args are used to pass a non-keyworded, variable-length argument list to a function, while kwargs are used to pass keyworded, variable-length argument list to a function.

Worried About Failing Tech Interviews?

Attend our webinar on
"How to nail your next tech interview" and learn

Ryan-image
Hosted By
Ryan Valles
Founder, Interview Kickstart
blue tick
Our tried & tested strategy for cracking interviews
blue tick
How FAANG hiring process works
blue tick
The 4 areas you must prepare for
blue tick
How you can accelerate your learnings
Register for Webinar

**args and **kwargs are special keyword arguments in Python, used to pass a variable number of arguments to a function. **args is used to send a non-keyworded variable length argument list to the function. **kwargs allows you to pass keyworded variable length of arguments to a function. Example: def myfunc(*args, **kwargs): for arg in args: print(arg) for key, value in kwargs.items(): print(key + " : " + value) myfunc(1, 2, 3, name="John", age="24") Output: 1 2 3 name : John age : 24

entroll-image