0% found this document useful (0 votes)
141 views

Python by Wipro

Python is a high-level, interpreted, interactive and object-oriented scripting language. It is designed to be highly readable and extensively used for web development, automation, data analysis, and more. Python code can be written and executed without compiling due to its interpreted nature. It supports object-oriented programming by allowing code to be organized into objects. Modules allow Python code to be logically organized and reused across programs.

Uploaded by

Pratik Sanas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
141 views

Python by Wipro

Python is a high-level, interpreted, interactive and object-oriented scripting language. It is designed to be highly readable and extensively used for web development, automation, data analysis, and more. Python code can be written and executed without compiling due to its interpreted nature. It supports object-oriented programming by allowing code to be organized into objects. Modules allow Python code to be logically organized and reused across programs.

Uploaded by

Pratik Sanas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Python Programming Language

Python Introduction:
Python is a high level, Interpreted, Interactive and Object-Oriented
Scripting Language.
Python is designed to be highly readable.

So, why is the python tutorial in the DevOps Book?

When we writing bash scripting for doing automation, slowly we


increased the complexity of our code. Our code became more and
more complex. Also, we don’t have any features in bash scripting
apart from just automating Linux tasks. Python is the easiest
programming language out there. Being easy it’s gives us lots of
feature and libraries Which extend the power of python. Python is
very extensible. We can use python to run Linux automation, Cloud
automation and several others. It is a very versatile in nature.

Python is Interpreted:
Python is processed at runtime by Interpreter. You don’t need to
compile your program before executing it. This is similar to PHP.

X
Saif Panjeshah
Technical Consultant
Python is Interactive:
You can actually sit at python prompt And Interact with the
Interpreter, directly to write your programs.

Python is Object Oriented:


Python Supports Object-Oriented Style or techniques of
programming that encapsulates code within the objects.

Python Supports the developments of wide range of applications.


from simple text processing to WWW browsers to games.

Installation of python:
• choco install python –pre

• Anaconda Distribution:
https://repo.anaconda.com/archive/Anaconda3-2022.05-
Windows-x86_64.exe

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
Pycharm Community Versions

Python on Linux, Version and Indentation:

X
Saif Panjeshah
Technical Consultant
Fig. Installation of python3 on Ubuntu
First code in Ubuntu by python3:
Invoke the Interpreter

Writing First python3 scripts


Interpreter Path: #!/usr/bin/env python3

X
Saif Panjeshah
Technical Consultant
Make it executable:

Run the code:

X
Saif Panjeshah
Technical Consultant
Difference between Bash Scripts & Python Indentation:

X
Saif Panjeshah
Technical Consultant
Resolving IndentationError: unexpected indent

X
Saif Panjeshah
Technical Consultant
Task 2:
Quotes & Comments:

X
Saif Panjeshah
Technical Consultant
• Variables:

#Multiple Assignments:

X
Saif Panjeshah
Technical Consultant
Mutable and Immutable Datatypes:

List:
• Mutable
• Collection of Multi Data types, enclosed in square brackets.

Tuple:
• Immutable
• Collection of Multi Data types, enclosed in round brackets.

X
Saif Panjeshah
Technical Consultant
• Dictionary: Elements are stored in Key & Value Pair (key:
value) Enclosed in Curly brackets.

X
Saif Panjeshah
Technical Consultant
Printing Format:

Slicing:

X
Saif Panjeshah
Technical Consultant
Slicing of a String, to get a Substring:

Slicing tuple:

X
Saif Panjeshah
Technical Consultant
Slicing List:

Slicing Dictionary:

X
Saif Panjeshah
Technical Consultant
Python Operators:
• Operators are the constructs which can manipulate the value
of operands. Consider the expression 4 + 5 = 9
• Here, 4 and 5 are called as Operands and “+” is called as
Operator.

• Types of Operators:
• Arithmetic operators.

• Assignment operators.

• Comparison operators.

• Logical operators.

• Identity operators.

• Membership operators.

• Bitwise operators.

X
Saif Panjeshah
Technical Consultant
Types of Operators:

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
Condition: if, else if, el if

Condition: Data Type

X
Saif Panjeshah
Technical Consultant
Loops:
Loops are used when you have a block of code that you want to
repeat it for fixed numbers of time or until a condition is not
satisfied.

While Loop:
Repeat the blocks of code until the while condition is true
Syntax:
While test_case:
Body of While

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
For Loop:
Repeat the block of code for a number of time.
Syntax:
For variable in sequence:
Body of For

Example of for Loop:

X
Saif Panjeshah
Technical Consultant
Example of Nested for Loop:

X
Saif Panjeshah
Technical Consultant
Break & Continue :

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
Pyramid Program :

X
Saif Panjeshah
Technical Consultant
Built-in Functions.
The Python interpreter has a number of functions and types built into it that are
always available. They are listed here in alphabetical order.

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
List:

X
Saif Panjeshah
Technical Consultant
Tuples:

X
Saif Panjeshah
Technical Consultant
Functions in python:
• It is used for resuability of code .

• A function is a block of code which only runs when it is called.


You can pass data, known as parameters, into a function. A
function can return data as a result.

X
Saif Panjeshah
Technical Consultant
If we printing function & not return anything in function it will be
print none.

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
How to resolve this Error using different Argument:
Default Argument:

X
Saif Panjeshah
Technical Consultant
Two Arguments:

Keywords Arguments :

X
Saif Panjeshah
Technical Consultant
Functions part – 2

Variable Length Arguments *args(Non Keyword Arguments):

X
Saif Panjeshah
Technical Consultant
Variable Length Argument(**kwargs Arguments):

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
Modules :

Installation of Modules:

X
Saif Panjeshah
Technical Consultant
Adding modern.py files

Adding call-modern.py files :

Run :

X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant
X
Saif Panjeshah
Technical Consultant

You might also like