Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to run Python functions in Eclipse command line?

I like to run a python function using the command line in Eclipse, just like running code from the normal Python Shell. How do I do that?
Rajendra Dharmkar
Answered on 7th Dec, 2017

We can use PyDev, which is a plugin for running Python programs from Eclipse. Once installed, we will have the option of running the applications themselves directly or from the PyDev console/command line.

How we can store Python functions in a Sqlite table?

I have this code where an employee class and employee function have been created., How to use sqlite3 to store and manipulate data through a python function?
Rajendra Dharmkar
Answered on 7th Dec, 2017

In the following code, we import sqlite3 module and establish a database connection. We create a table and then insert data and retrieve information from the sqlite3 database and close the connection finally.#sqlitedemo.py import sqlite3 from employee import employee conn = sqlite3.connect('employee.db') c=conn.cursor() c.execute(‘’’CREATE TABLE employee(first text, last text, pay ... Read More

How to pass a json object as a parameter to a python function?

I have a json object as follows , How to pass this json object to a python function?
Rajendra Dharmkar
Answered on 7th Dec, 2017

We have this code below which will the given json object as a parameter to a python function.import json json_string = '{"name":"Rupert", "age": 25, "desig":"developer"}' print type (json_string) def func(strng):     a =json.loads(strng)     print type(a)     for k, v in a.iteritems():           ... Read More

How to return a json object from a Python function?

I have a python dictionary as follows, How do I return this dictionary from a python function as a json obect?
Rajendra Dharmkar
Answered on 7th Dec, 2017

We return a json object from a python function as follows using given python dictionary.import json a = {'name':'Sarah', 'age': 24, 'isEmployed': True } # a python dictionary def retjson(): python2json = json.dumps(a) print python2json retjson()OUTPUT{"age": 24, "isEmployed": true, "name": "Sarah"}

How to pass a dictionary as argument in Python function?

I have a dictionary as follows , How do I pass above dictionary as an argument to a python function?
Rajendra Dharmkar
Answered on 7th Dec, 2017

In the code given below we pass given dictionary as an argument to a python function and then call the function which works on the keys/value pairs and gives the result accordinglyd = {'a' : 1, 'b' : 2, 'c' : 3} def f(dict):     for k, v in ... Read More

How can you execute functions with multiple arguments at a terminal?

I have a python function defined with multiple arguments as follows: , How do I execute this function at a terminal?
Rajendra Dharmkar
Answered on 7th Dec, 2017

We first import the sys module. We have to use the argv function of the sys module to fetch the arguments of the function entered at the terminal and execute the function.#fubar.py import sys def print_funcargs(arg1, arg2, arg3):       print arg1 + ' '+ arg2 + ' ' ... Read More

Why and how are Python functions hashable?

I have a function f() and a lambda function lambda x:1 as follows , Are these functions or all functions hashable?
Rajendra Dharmkar
Answered on 7th Dec, 2017

An object is said to be hashable if it has a hash value that remains the same during its lifetime. It has a __hash__() method and it can be compared to other objects. For this, it needs the __eq__() or __cmp__()method. If hashable objects are equal when compared, then they ... Read More

Why does Python code run faster in a function?

It is found that if python code is run normally and then if it is run in a python function, it runs faster in the latter case. I want to know why python code runs faster in a function.
Manogna
Answered on 7th Dec, 2017

It is found that if python code is run normally and then if it is run in a python function, it runs faster in the latter case. I want to know why python code runs faster in a function.It is generally found that it is faster to store local variables ... Read More

How exactly do Python functions return/yield objects?

I have the following code snippets , How do python functions in these codes and in general return/yield objects?
Manogna
Answered on 7th Dec, 2017

The return statement causes a python function to exit and give back a value to its caller. The purpose of functions in general is to take in inputs and return something. A return statement, once executed, immediately terminates execution of a function, even if it is not the last statement ... Read More

Which is more fundamental between Python functions and Python object-methods?

I have a function defined and object-method as follows , Which is more fundamental between a python function and a python object-method?
Manogna
Answered on 7th Dec, 2017

A function is a callable object in Python, i.e. can be called using the call operator. However other objects can also emulate a function by implementing __call__method.  For example:def a(): pass # a() is an example of function print a print type(a)OUTPUTC:/Users/TutorialsPoint/~.py <function a at 0x0000000005765C18> <type 'function'>A method is ... Read More

How do you test that a Python function throws an exception?

How do I use the unittest module to test if a function throws an exception or not? How do I test if a function involving addition of an integer and a string throw an exception or not?
Manogna
Answered on 7th Dec, 2017

We write a unittest that fails only if a function doesn't throw an expected exception.We also test if a Python function throws an exception.For example, see the sample code we paste into the Python shell to test Python's type-safety:import unittest class MyTestCase(unittest.TestCase):         def test_1_cannot_add_int_and_str(self):     ... Read More

What are the allowed characters in Python function names?

Are some characters other than alphabets, numbers and underscores allowed in python names or python identifiers? If yes, what are those characters?
Manogna
Answered on 7th Dec, 2017

Python IdentifiersIdentifier is the name given to entities like class, functions, variables etc. in Python. It helps in knowing one entity from another.Rules for writing identifiersIdentifiers can be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore ... Read More

What are default arguments in python?

Does python allow function arguments to have default values? Does the argument gets its default value if the function is called without the argument?
Manogna
Answered on 7th Dec, 2017

Python allows function arguments to have default values; if the function is called without the argument, the argument gets its default valueDefault arguments:Python has a different way of representing syntax and default values for function arguments. Default values indicate that the function argument will take that value if no argument ... Read More

What are required arguments of a function in python?

I have this python code. , When this code is run, I get an error for the second function call with a single argument. In this context, what are required arguments of a function in python?
Rajendra Dharmkar
Answered on 7th Dec, 2017

Required arguments are the mandatory arguments of a function. These argument values must be passed in correct number and order during function call. If you run the given code you get the following outputHi 15 Traceback (most recent call last):   File "requiredarg1.py", line 4, in <module>     requiredArg('Hello') TypeError: ... Read More

How to return void from Python function?

I have this code , Why are the functions in this code all returning None in this code?
Rajendra Dharmkar
Answered on 7th Dec, 2017

Since Python is dynamic-typed and you don't specify a return type when defining a function, then you can return anything with any type, that includes None which is the default return value (when you don't return anything, the function actually returns None at the bottom of function)Functions like this are ... Read More

Advertisements
Loading...
Unanswered Questions View All

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.