Wednesday, 20 September 2017

3)Python Statement, Indentation ,Comments and DocString

Python Statement, Indentation ,Comments and DocString

Python Statements:
Instructions that a Python interpreter can execute are called statements.

Example:
a=10
if statement, for statement, while statement etc.
Two types of Python Statements:

  1. Single line statement
  2. Multi-line statement,

1.Single line statement:
Instructions are end with in a line

Example:
a=10
2.Multi-line statement:
Multi-line statement extend over multiple lines with the line continuation character (\).

Two types of continuations:
Explicit continuation ==> using \ character
Implicit continuation ==> using brackets [] or braces {} 

Example:



Note:
We can also put multiple statements in a single line using semicolons,

Example:
a=20; b=10; c=30
Python Indentation:

Most of the programming languages like C, C++, Java use braces { } to define a block of code. But Python uses indentation 

Note:
A code block (body of a function, loop etc.) starts with indentation and ends with the first unindented line.

Indetation ==> Whitespaces , prefered is tabs, we can use any amount of space, but should be consistent
Incorrect indentation will result into IndentationError


Python Comments:

Comments are very important while writing a program.

Note:

  • It describes what's going on inside a program so that a person looking at the source code does not have a hard time figuring it out
  • Basically, helpful to give the program logic for understandability


Hash (#) symbol to start writing a comment.

Two types of comments:

  1. Single line comments ==> using #
  2. Multi-line comments ==> using either ''' ''' or """ """

Docstring in Python:

Docstring is short for documentation string.

Note:
It is a string that occurs as the first statement in a module, function, class, or method definition. We must write what a function/class does in the docstring.

Syntax:

Within tuples quotes
""" """ 

Docstring is available to us as the attribute __doc__ of the function.



Previous page                                                                                                         Next page

5 comments:

  1. Staying compliant as a landlord can be challenging, especially with ever-changing safety and certification requirements. Resources like Landlord Certification are helpful for understanding inspections, certificates, and best practices. Having clear guidance makes managing rental properties much more straightforward and stress-free.

    ReplyDelete
  2. Your explanation of Python's advantages, especially the extensive libraries and easy syntax, is spot on. As someone who transitioned from manual testing to automation, I found that structured training made all the difference. For learners in Electronic City who want to build practical, job-ready skills, I strongly suggest real time software testing projects training in electronic city. Working on live projects alongside Python scripting helped me understand how to build robust test frameworks from scratch. Does your institute offer any hands-on Python projects as part of the training? That would be a great addition to this already helpful post.

    ReplyDelete

Fundamentals of Python programming

Fundamentals of Python programming: Following below are the fundamental constructs of Python programming: Python Data types Python...