Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

What kind of variable is this? (Python Lambda Function)

 
Ranch Hand
Posts: 205
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A piece of code within a lambda function on AWS which never made sense to me:


The last line (line #8) where it says: `RequestItems=request_items`
What kind of variable is "RequestItems?"
And why does it show up as "red" (as if it's an error something) within an IDE, such as IntelliJ?
 
Saloon Keeper
Posts: 12613
273
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a so called "keyword argument", but this is an absolutely terrible name, so I will call them "named argument" instead.

When you call a function in python, you can explicitly name the parameter that you want to assign an argument to.

RequestItems is a parameter of the batch_write_item function, and you're naming it explicitly when assigning request_items to it.
 
Sheriff
Posts: 22055
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's a great way to handle multiple optional arguments. Suppose you have a method like this:

You need to pass the first two required arguments, but if you want to additionally only use a non-default value for the third optional, you call it like this:

 
Destroy anything that stands in your way. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic