Input! and User Defined Fucntions

Input!

we need to ask the user for input.
name = str(input("What's your Name?"))
In the above example, str(input("")) accepts a string, prints it, and then waits for the user to type something and press Enter (or Return).
In the interpreter, Python will ask:
What's your Name?
Once you type in your name and hit Enter, it will be stored in Name.



   Indentation in PYTHON   
    Python follows a particular style of indentation to define the code since Python                      functions don't have any explicit beginning or end, like curly braces, to indicate the start        and stops for the function: they have to rely on this indentation. Indentation is shifting       of statement to the right of another statement.
           A
             B (under A)
               C(under B)
                 D(under C)
                 E(under C at the same level as D)
               F(under A at the same level as B and C)
           G(at the same level as A)
example:

 def func():                             
 print("Hello learner !")         
                                               
 func()                                     

✶     COMMENTS 


Comments are statements in a script that are ignored by the PYTHON Interpreter and, therefore, have no effect on the actual output of the code. Comments make the code more readable and understandable for human beings. This makes us revision/modification of the code easier by the original author of the code and also by some new author who has been assigned the responsibilities.

A Comment in Python starts with a hash symbol(#) anywhere in a line and extends till the end of the line and we can also add a Comment in Python using ''' Your comments '''.


example:
>>>#This is the Comment.
>>>x='tushar'
>>>y='gahora'
>>>print(x + y)

output:




tushargahora
       

  *  User-Defined Functions                                                                                                                    


A Function is a group of statements that exists within a program for the purpose of performing a specific task. Instead of writing a large program as one long sequence of instructions, it can be written as several small functions, each one performing a specific part of the task.

How to define and call a Function in Python
A user-defined Python function is created  or defined by the def statement followed by the function name and pranthesess[()] 

def function_name(comma_separated_list_of_parameters):
""docstring""
Keyword
statement(s)









2 comments:

Powered by Blogger.