from the book

prime numbers


In [11]:
print("start")
c=input("enter number")
a=int(c)
flag=0
i=2;
while (i<a):
    for r in range(2,a-1):
        z=a%r
        i+=1
        if(z==0):
            flag=1
if (flag==0):    
    print("prime number")
else:
    print("not prime")


start
enter number7
prime number

In [1]:
'book'+'club'


Out[1]:
'bookclub'

In [2]:
"book"-"book"


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-980cf993484f> in <module>()
----> 1 "book"-"book"

TypeError: unsupported operand type(s) for -: 'str' and 'str'

In [3]:
"book"/"club"


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-9c9cf11095e9> in <module>()
----> 1 "book"/"club"

TypeError: unsupported operand type(s) for /: 'str' and 'str'

In [4]:
"book"*"club"


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-637456a8af25> in <module>()
----> 1 "book"*"club"

TypeError: can't multiply sequence by non-int of type 'str'

In [5]:
"book"*3


Out[5]:
'bookbookbook'

In [6]:
True + True


Out[6]:
2

In [7]:
True+ False


Out[7]:
1

In [8]:
True-False


Out[8]:
1

In [9]:
True- True


Out[9]:
0

In [2]:
def say_hello():
    print("hello")
say_hello()


hello

In [4]:
def add(a,b):
    print("a+b=",a+b)
add(2,3)
x=2
y=9
add(x,y)


a+b= 5
a+b= 11

In [8]:
def function(a=10,b=4,c=9):
    print("\n a=",a,"\n b=",b ,"\n c=",c)
function(3,5)


 a= 3 
 b= 5 
 c= 9

In [9]:
def maxim(a,b):
    if a>b:
        return a
    else:
        return b
a=2
b=3
print("maximum is",maxim(a,b))


maximum is 3

In [ ]:
help()


Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> def
Function definitions
********************

A function definition defines a user-defined function object (see
section *The standard type hierarchy*):

   funcdef        ::= [decorators] "def" funcname "(" [parameter_list] ")" ["->" expression] ":" suite
   decorators     ::= decorator+
   decorator      ::= "@" dotted_name ["(" [parameter_list [","]] ")"] NEWLINE
   dotted_name    ::= identifier ("." identifier)*
   parameter_list ::= (defparameter ",")*
                      | "*" [parameter] ("," defparameter)* ["," "**" parameter]
                      | "**" parameter
                      | defparameter [","] )
   parameter      ::= identifier [":" expression]
   defparameter   ::= parameter ["=" expression]
   funcname       ::= identifier

A function definition is an executable statement.  Its execution binds
the function name in the current local namespace to a function object
(a wrapper around the executable code for the function).  This
function object contains a reference to the current global namespace
as the global namespace to be used when the function is called.

The function definition does not execute the function body; this gets
executed only when the function is called. [3]

A function definition may be wrapped by one or more *decorator*
expressions. Decorator expressions are evaluated when the function is
defined, in the scope that contains the function definition.  The
result must be a callable, which is invoked with the function object
as the only argument. The returned value is bound to the function name
instead of the function object.  Multiple decorators are applied in
nested fashion. For example, the following code

   @f1(arg)
   @f2
   def func(): pass

is equivalent to

   def func(): pass
   func = f1(arg)(f2(func))

When one or more *parameters* have the form *parameter* "="
*expression*, the function is said to have "default parameter values."
For a parameter with a default value, the corresponding *argument* may
be omitted from a call, in which case the parameter's default value is
substituted.  If a parameter has a default value, all following
parameters up until the ""*"" must also have a default value --- this
is a syntactic restriction that is not expressed by the grammar.

**Default parameter values are evaluated from left to right when the
function definition is executed.** This means that the expression is
evaluated once, when the function is defined, and that the same "pre-
computed" value is used for each call.  This is especially important
to understand when a default parameter is a mutable object, such as a
list or a dictionary: if the function modifies the object (e.g. by
appending an item to a list), the default value is in effect modified.
This is generally not what was intended.  A way around this is to use
"None" as the default, and explicitly test for it in the body of the
function, e.g.:

   def whats_on_the_telly(penguin=None):
       if penguin is None:
           penguin = []
       penguin.append("property of the zoo")
       return penguin

Function call semantics are described in more detail in section
*Calls*. A function call always assigns values to all parameters
mentioned in the parameter list, either from position arguments, from
keyword arguments, or from default values.  If the form
""*identifier"" is present, it is initialized to a tuple receiving any
excess positional parameters, defaulting to the empty tuple.  If the
form ""**identifier"" is present, it is initialized to a new
dictionary receiving any excess keyword arguments, defaulting to a new
empty dictionary. Parameters after ""*"" or ""*identifier"" are
keyword-only parameters and may only be passed used keyword arguments.

Parameters may have annotations of the form "": expression"" following
the parameter name.  Any parameter may have an annotation even those
of the form "*identifier" or "**identifier".  Functions may have
"return" annotation of the form ""-> expression"" after the parameter
list.  These annotations can be any valid Python expression and are
evaluated when the function definition is executed.  Annotations may
be evaluated in a different order than they appear in the source code.
The presence of annotations does not change the semantics of a
function.  The annotation values are available as values of a
dictionary keyed by the parameters' names in the "__annotations__"
attribute of the function object.

It is also possible to create anonymous functions (functions not bound
to a name), for immediate use in expressions.  This uses lambda
expressions, described in section *Lambdas*.  Note that the lambda
expression is merely a shorthand for a simplified function definition;
a function defined in a ""def"" statement can be passed around or
assigned to another name just like a function defined by a lambda
expression.  The ""def"" form is actually more powerful since it
allows the execution of multiple statements and annotations.

**Programmer's note:** Functions are first-class objects.  A ""def""
statement executed inside a function definition defines a local
function that can be returned or passed around.  Free variables used
in the nested function can access the local variables of the function
containing the def.  See section *Naming and binding* for details.

See also: **PEP 3107** - Function Annotations

     The original specification for function annotations.


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: