python - How to access the keys and values of dictionary passed as argument in method -


itemprop = "text">

I have AC # backgrounds and I'm trying to pass a dictionary in the law and some have to see if I Whether a particular key is present or not, if it is present in the key dictionary and then I want to do some other things.

Suppose that the following dictionaries are:

  tel = {'jack': 4098, Sape ': 4139}  

And I want to check whether the 'saip' exists or not? In some way in the method, I do not know the type of argument. How can I put in the dictionary to retrieve keys and values.

In the method I want to check:

  keys = tel.keys ();  

However, in the law, I do not have information about the type of argument nearby.

Python has not been written like C #. The data types of parameters in the function / method signature are not included. So you do not need to put the value passed in a dictionary. Instead you believe that whatever has been passed is a dictionary and working on it. If you expect that any other thing other than the dictionary will be passed then you can use it to catch any issue or you can use the checks to check what you expect . It is being said that casting is present in the dragon; For example, you can convert int 1 from str 1 to string.

Also keep in mind that if the keyword is used in , then it will work for any non executable dictionary only. / P>

Example:

  & gt; & Gt; & Gt; In 'Jack', 'Larterjack' True & gt; & Gt; & Gt; Tell = {'Jack': 40 9 8, 'ASP': 4139} & gt; & Gt; & Gt; 'Jack' True & gt; & Gt; & Gt;  

If you really want to see that there is a glossary, then you can do this:

  & gt; & Gt; & Gt; Isinstance (tele, dict) is true  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -