Skip to main content

Python tutorial - #3 (Docstrings and Data-Type)



Docstrings = If we write string inside triple single quote (‘’’----‘’’) or triple double quote (“””----“””) and if these strings are written as first statements in a module, function, class or a method. Then these strings are called Documentation strings or simply Docstrings. These strings are useful to create an A.P.I documentation file from python program, An A.P.I (Application Programming Interface) documentation file is a text file or HTML file that contains the description of all features of software or product. When software is created it is the duty of programmer to create docstrings file in which they explain each and every class, Module, function etc. properly. It helps the user of the product (software) to use this smoothly.

Representing Binary, Octal and Hexadecimal number.

➠In python, Binary number are represented by adding 0 (zero) B or 0 (zero) b as prefix to each binary number.
Example: - 0B11001, 0b00101 etc.
                         Octal number in python are represented by adding 0 (zero) O or 0 (zero) o as prefix to each octal number. Example: - 0O12364, 0o12523, etc.
                                      And at last, Hexadecimal number are represented by adding o (zero)X or 0 (zero)x as prefix to each number. Example: - 0x11fb9, 0XA180, etc.

 Program - #1


Datatype Conversion

Changing of data from one datatype to another are called datatype conversion.
  Program- #2

Bool datatype = Bool datatype represent Boolean value. There are two Boolean values ---True and False. Python internally represents True as 1 and False as 0.

Program- #3


➢Here, there is a comparison between n1 (25) and n2 (21) in which it returns True in fourth line. thus, it execute the fifth line object. If fourth line returns False, then else statement executes. Observe this in the given program.

Program - #4

Literals in python:--

Literals are the value that stored in variable of a program.
    ⇨ Here, '21' is a literal value.

There are three types of literal:-
a) Numeric literal
    ⇨ Here, 1222 is a numeric literal

b) Boolean literal
c) String literal
    ⇨ Here, 'Hello World' is a string literal

Escape character

Escape character are useful to perform a different task. At first, observe the given some important escape characters.


Program - #5

Determining the datatype of a variable

To know, the datatype of variable or object we can use type() function.
Program - #6

Program - #7


User defined datatype = the datatype which are created by the programmers are called user-defined datatype. An Array, class, module are some examples of user-defined datatype.

Constant in Python

A constant is similar to a variable but its value cannot be modified or changed in the course of the program execution.
For example: - In Mathematics value of ‘Pi’  is always  22/7 and it is not possible to changed them. Constant in Python are same as.

Identifiers

An identifier is a name the is given to a variable or function or class etc.
Example:- num = 67
               ⇨  Here, 'num' is an Identifier
                 
                 str = 'Hello world'
               ⇨  Here, 'str' is also an Identifier

➠Identifier can include letters, numbers and the underscore character(_) They should always starts with a non numeric characters. Special symbols such as ?,#,$,% and @ are not allowed in identifier.

Note  Python is a case sensitive programming language, it means capital letters and small letters are identified separately by python.

Example – 'num' and 'Num' are treated as different names and hence represents different variables.  


Comments

Popular posts from this blog

Python tutorial - #4 (Operators in Python)

OPERATORS IN PYTHON The general purpose of a program is to accept data and perform some operations on the data. The data in the program is stored in variables. The next question is how to perform operations on the data. For example, when a programmer wants to add two numbers, he simply type '+' symbol. This symbol performs addition operation. Such symbols are called operators. ⇨ Operator = An operator is a symbol that performs an operation.  When an operator acts on some variables then it is called operands . Example :- a + b in the given equation '+' operator acts on two operands 'a' and 'b'. If an operator acts on single operands then it is called unary operator . And when an operator acts on two operands then it is called binary operator . And when an operator acts on more than two operands (variable) It is called Tertiary operator . ➠Classifications of Operator -- a) Arthimatic operators b) Assignment operators c) Unary minu...

Python tutorial - #5 (Operators in Python)

Membership Operators This operator helps us to check an element is found in a sequence or not. It gives there result in Boolean value (True or False). ➥There are two types of Membership operator :- a) in b) not in ➢in membership operator This membership operator returns True if an element is found in a sequence and it returns  False When an element is not found in a sequence. Program - #1 ➢not in membership operator This membership operator returns True if an element is not found in a sequence and it returns False if an element is found in a sequence. Program = #2 Identity Operators This operator helps us to check whether two element are same or not. Actually, this operator compares the memory location of two object, if the memory locations are same then objects are also same otherwise the objects are not same.                                      ...

Python tutorial - #6 (Control statements)

Control Statements When we write a simple program, generally it executes line by line and this execution are called sequential execution. This type of execution is suitable only for developing simple programs. It is not suitable for developing complex programs. To develop a program which contains complex logic. Then we need to execute statements according to our requirement for this we uses Control statements in which we can control the statements according to our need.  ➠ There are types of control statements in Python:- a) If... statements b) If... else.. Statements c) If...elif....else.. Statements  d) While loop  e) For loop f) Nested loop  g) Else suit h) Continue statements  i) Break statements j) Pass statements  k) Assert statements l) Return statements  ↷If... statements    Syntax:-  if condition:                 Statements Here, at first...