0% found this document useful (0 votes)
29 views7 pages

Python Digital Notes

The document provides an overview of Python, a high-level programming language known for its readability and ease of use. It covers key features, types of tokens, input/output statements, debugging methods, data types, type casting, control statements, and data structures like lists and dictionaries. Additionally, it explains mutable and immutable data types, as well as various control flow mechanisms including decision-making, iteration, and jump statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views7 pages

Python Digital Notes

The document provides an overview of Python, a high-level programming language known for its readability and ease of use. It covers key features, types of tokens, input/output statements, debugging methods, data types, type casting, control statements, and data structures like lists and dictionaries. Additionally, it explains mutable and immutable data types, as well as various control flow mechanisms including decision-making, iteration, and jump statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DIGITAL NOTES - IP

Unit - 2 Python
v Python
 Python is a high level programming language which was developed by Sir Guido van
Rossum in 1991.

 It is known for readability and easy to use, making it popular among all types of
experience software developer and also popular for beginners.

v Features of Python
1. Used for software development

2. Library based language

3. Free and open source language

4. User friendly language

5. Easy and less code programming language

v Token
 A token is the smallest unit or component of a python program which act as a
building block of the language.

 The python interpreter breaks down the source code into these tokens during the
analysis before processing it.

v Types of Token
1. Keywords

Keywords are the reserved words in Python that has special functions and cannot be used as
the identifiers.

2. Identifiers
There are names given to variables, functions, classes, modules or other entities in the code
called identifiers. They must follow some specific naming rules.

3. Literals

The literals represents fixed value in the code. It can be numbers ( integers , floats ) ,
boolean ( true , false ) , string or other special value like none.

4. Operators

Operators can be defined as symbols that are used to perform operations on operands.
There are various types of operators in python -

Ø Arithmetic Operators
Ø Relational Operators
Ø Logical Operators
Ø Assignment Operators
Ø Membership Operators
Ø Bitwise Operators
Ø Identity Operators

5. Punctuators

These are some symbols used to structure the code and separate different parts of the
program.

v Input and Output Statement


Ø Input Statement

The input function is used to obtain input to the console by the keyboard.

Syntax: variable = input (”prompt_message”)

Ø Output Statement

The print function is used to display output to the console.

Syntax: print ( object1, object2, - - - , sep =”,” , end=”/n”)

v Debugging
 In Python, the debugging process involves identifying, analysing or resolving errors
for unexpected behaviour in our code.

 Several methods and tools are available for this purpose named as debugger.
 In python, the debugging process is facilitated by pdp module. It is in-built to the
python library.

 The major advantage of pdp, is it runs purely in the command line, thereby making it
great for debugger code on remote servers.

 It supports setting breakpoints, stepping throughcode, source code listing and


viewing stack traces.

v Datatypes in Python
 Python datatypes are the classification or categorization of the data items.

 It represents the kind of value that tells what operation could be performed on a
particular data.

 Python is dynamically typed, meaning of the data types of a variable is inferred when
a value is assigned without explicit declaration.

 Examples of Datatypes : Numeric, Sequence, Mapping, Boolean, Set Type, Binary


Type.

v Datatype Conversion or Type Casting


 In Python, data type conversion is also known as type casting. It involves changing a
value from one data type to another.

 This conversion is crucial when operations require compatibility between different


data types. It is mainly of 2 types -

Ø Implicit Type Conversion

This type of conversion typically occurs during operation involving different data types,
where python converts the similar datatypes to larger one to prevent data losses.

Ø Explicit Type Conversion

In the explicit type conversion the user explicity convert a data type using in-built features.
This is done when a specific data type is required for operation or to prevent data loss.

v Mutable and Immutable Datatype


Ø Mutable Datatype
 Mutable object or data type are those, whose internal state or content can be
modified after their created without creating a new object.

 In simple words, the mutable datatypes are the changeable datatypes.


 Eg. - List, Dictionary, Sets, etc.
Ø Immutable Datatype

 The immutable datatype are those , whose values cannot be or altered once we are
created.

 In any operation that appear to modify as immutable object, actually creates a new
object.

 Eg. - Numbers , Strings, Tuples , etc.

v Control Statements
 Control statements are used to control the flow of execution depending upon the
specified conditions of logic.

 They are of three types -

1. Decision Making Statements

2. Iteration Statements

3. Jump Statements

v Decision Making Statements


Decision making statements are used to control the flow of execution of program depending
upon the conditions. They are of three types -

Ø If Statement

If statement executes some code if test expression is true (non-zero) and nothing if the
condition isn’t fulfilled.

Ø If - Else Statement

If - Else Statement execute some code if the text expression is true ( non-zero) and some
other code if the text expression is false.

Ø Nested If - Else Statement


The nested if - else statement allows us to check for multiple test expressions and execute
different codes for more than two conditions.

v Iteration Statements ( Loops )


 Iteration statements are used to execute a block of statement as long as the
condition is true.

 Loop statements are used to run the same code again and again. They are also of
three types -

Ø While Loop

 While loop is used to execute a block of statement as long as the given condition is
true.

 When the condition becomes false, the control will come out of the loop. The
condition is checked everytime at the beginning of the loop.

Ø For Loop

 For loop is used to iterate over items of an sequence, such as a list or a string ( loop
means repetition of the task again and again ).

Ø Nested For Loop

 A nested for loop in Python involves placing one for loop inside another loop. The
structure is needed when we need to iterate over elements in a multidimensional.

v Jump Statements
 Jump statements are used to transfer the programs control from one place to
another.

 It means these are used to change the flow of our loop. They are also of three types -

Ø Break Statement

Break statement is used to terminate the loop.

Ø Continue Statement

Continue statement is used to skip all the remaining statements in the loop and moves
control back to the top of the loop.

Ø Pass Statement
The pass statement does nothing. It can be used when a statement is required syntactically
but the program required no action.

v Lists
 List is a collection of items and each item has its own index value. Index of first item
is 0 and the last item n-1. Here n is the number of items in a list.

 Lists are enclosed in square brackets and each item is separated by a comma. Passing
value in the list while declaring list is initialising of a list.

 A lot of things could be done with the lists in python such as -

q Create a blank list

q Access item from list

q Iterate item through list

q Slicing a list

q Add and delete an item from a list

q Add two lists

v Dictionary
 Dictionary is an unordered collection of items where each item consists of a key and
a value.

 The item of a dictionary( value ) is mutable, but the key of an item must be
immutable and unique.

 Dictionary is enclosed with curly braces and each item is separated from other item
by a comma. Within each item, the key and value are separated by a colon (:).

 Passing the value in a dictionary at declaration is dictionary initialisation.

 As in list, a number of things could also be done with the dictionary-

q Creating a dictionary

q Accessing list item from dictionary

q Iteration through a dictionary

q Updating aur manipulating dictionary

v Escape Sequence

You might also like