Tuesday, May 22, 2018

Python chap 3(Basic syntax:Hi friends this is the continuation of previous post so i kindly request you to read that before this post. As this blog is also prepared for beginners so i advice you that you don't need to by-heart this lessons just read and understand it if you have any doubt ask in the comment section )

    

MULTI-LINE STATEMENT

                        In python the end of physical line marks the end of the statements and if there is a necessity of  multiple lines of code to be used python uses a backslash at the end of the line if there is no comment after the line and the other code comes as next line then it will be considered as one line in the code as example here a code is given 
if 2000<year<3000 and 1<= date<=30\
    and 1<=hour<=24 and 1<=minutes<=60\
    and 1<=seconds<=60:
             return 1
if you don't understand the code leave code and focus on backslashes that is our job if you are not sleeping you can see that more on codes will be explained in the coming lessons and the other thing to note here is that the statements contained within the [],{},() doesn't need the backslashes to use because it can identify the line using this braces like the statement given below :

animal_names = [cat,dog,fish,cow,camel,goat,     #here comes the comment
               sheep,wolf,bear,elephant,snake,
               dolphin,peacock,cat,whale,pigeon]                                        

                             Comments

A comment is used to it is a programmer readable part in the code which is ignored by the interpreters and compilers it is used for the purpose of humans to understand the source code. In python the comment starts with a # character which is not part of string literal and ends at the end of that same physical line . And also the comment signifies the end of the logical line and there is this other case that logical line is in a way which the statement is inside the braces like the statement given above it doesn't depict as end of the statement

here is an example of comment in single line
#here is the single line command
there is no appropriate multiline commenting feature for python but you can do it by commenting each line individually or there is a little difficult way like triple quotes which has a problem when you are inside a class you should indent it properly simply you can use it when they are not a docstring an example is given below as 



#this is the first comment
#this is the second comment
#this is the third comment
"""
This is a
multi line comment

"""
"""
    def future_code(self,url):
           here it is not a
           proper code it is for
           example that you should
           indent here properly

"""

Quotations in python

The python uses single('single quotes')  double("double quotes") and triple quotes("""triple quote""" or '''triple quote''' ) to denote string literals as long as the same type of quotes starts and ends the string literals the triple quotes are used for the multiple string lines 
here are some examples 
animals = 'this is animals '
machines = "this is double quotes"
birds = """this is triple quotes
here it is in multiple lines"""

USE SEMICOLON TO ADD MULTIPLE STATEMENTS ON A SINGLE LINE

Can use multiple statement on a single line with the use of semicolons like in the statements given below

if x<y;print('x');print('y')

USE COLONS ON COMPOUND STATEMENTS

A compound statements consists of one or more clauses A clause consists of a header and a suite a clause header of a particular compound statement are all at the same indentation level each clause header begins with a uniquely identifying keyword and ends with colon a suite is a group of statements controlled by the clause a suite can be made with one or more colon separated simple statements on the same line as the header following the headers colon or it can  one or more indented statements on subsequent lines only this indented statements can contain nested compound statements as example given here

if expression:
      suite
elif expression:
     suite
else:
    suite


COMMAND LINE ARGUMENTS
In the command line we can start a program with additional arguments this arguments are passed in to the programs many programs can be run to provide you with information  about how they should be run python enables you to do this with -h- you can program your script in such a way it should accept various options command line arguments is an advanced topic we will come to that later

that's all for this post

THANKS FOR VIEWING MY BLOG HOPE YOU LIKE THE POST IF YOU WANT TO GET LATEST POSTS ON THIS PLEASE FOLLOW BY EMAIL ID AND FEEL FREE TO ASK YOUR DOUBTS AND DON'T FORGET TO SHARE,COMMENT AND FOLLOW 

No comments:

Post a Comment