Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

The get() method on Python dicts and its "default" arg

# The get() method on dicts
# and its "default" argument

name_for_userid = {
    382: "Alice",
    590: "Bob",
    951: "Dilbert",
}

def greeting(userid):
    return "Hi %s!" % name_for_userid.get(userid, "there")

>>> greeting(382)
"Hi Alice!"

>>> greeting(333333)
"Hi there!"
Comment

PREVIOUS NEXT
Code Example
Python :: difference() Function of sets in python 
Python :: Comparing Sets with issubset() Function in python 
Python :: A Python program to demonstrate inheritance 
Python :: Shallow copy in python and adding another array to list 
Python :: web parser python 
Python :: how to use print function in python stack overflow 
Python :: pygame lerp 
Python :: getroot xml python 
Python :: logged_passengers 
Python :: pandas get most occurring value for each id 
Python :: handling files in django 
Python :: python zeep- SOAP protocol -WSDL/XSD?XML 
Python :: sklearn list parameters 
Python :: clear list in python 
Python :: how to give tab space in python 
Python :: zufälliger wert aus liste python 
Python :: python recognize lower and upper case user input 
Python :: python return multiple value from a function using a dictionary 
Python :: jax.numpy 
Python :: selenium restart browser python 
Python :: how to delete lists after using them in python 
Python :: una esfera solida de radio 40 cm tiene una carga positiva 
Python :: mylist = [“hello”, “bye”,”see ya”,”later”] phrase = mylist[1] 
Python :: list to string without loop 
Python :: python code to display a grid of data table 
Python :: django composer 
Python :: Implement a function word_list() that reads the 5_letter_words.txt file and returns a list of the words in the file. 
Python :: py random.smple 
Python :: const obj = { a: 1, b: 2, c: 3, }; const obj2 = { ...obj, a: 0, }; console.log(obj2.a, obj2.b); 
Python :: comment analyser la différence de pixel entre deux images python 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =