0% found this document useful (0 votes)
5 views59 pages

01PY P-1 Introduction

This document is a comprehensive Python tutorial aimed at beginners, covering basic to advanced concepts of Python programming. It includes topics such as data types, variables, operators, and practical coding examples, as well as career possibilities in Python-related fields. The tutorial emphasizes the importance of hands-on practice and provides guidance on setting up the Python environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views59 pages

01PY P-1 Introduction

This document is a comprehensive Python tutorial aimed at beginners, covering basic to advanced concepts of Python programming. It includes topics such as data types, variables, operators, and practical coding examples, as well as career possibilities in Python-related fields. The tutorial emphasizes the importance of hands-on practice and provides guidance on setting up the Python environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Python

This Python tutorial has been written for the


beginners to help them understand the basic to
advanced concepts of Python Programming
Language.

Venu Prakash Reddy


SCTIPT WAVE
2023

Motivation
Programming isn't about what you know; it's about
what you can figure out

The only way to learn a new programming language is


by writing programs in it

PYTHON ZERO TO HERO


SCTIPT WAVE
2023

Problem solving

PYTHON ZERO TO HERO


SCTIPT WAVE
2023

Programing
Coding, sometimes called computer programming,
is how we communicate with computers.

Code tells a computer what actions to take, and writing


code is like creating a set of instructions.
By learning to write code, you can tell computers what
to do or how to behave in a much faster way.

PYTHON ZERO TO HERO


SCTIPT WAVE

PYTHON CAN USED FOR


01 02 03 04

DATA NETWORK DATABASE


WEB-DEV ACCESS
SCIENCE PROGRAMMING

05 06 07

GAMES & 3D ML AI EDUCATION


GRAPHICS
PYTHON ZERO TO HERO
PYTHON CARRER POSSIBILITIES

Web Data Scientist ML Engineer AI Researcher AI Engineer


Development Analyze and interpret Develop and deploy machine Conduct research in AI, Develop AI-powered
Work on both front-end complex data, build applications and
learning models for various deep learning, and
and back-end predictive models, and systems using Python
applications, including reinforcement learning to
development using make data-driven decisions libraries and frameworks
natural language processing, advance the field.
Python web frameworks using libraries like NumPy,
computer vision, and like TensorFlow and
like Django or Flask. pandas, scikit-learn, and
recommendation systems. PyTorch.
TensorFlow

Data Engineer DevOps Engineer Site Reliability Security Analyst


Engineer (SRE) Identify and mitigate
Build and maintain data Automate deployment, Ensure the reliability and security vulnerabilities,
pipelines, ETL processes, configuration management, scalability of web perform penetration testing,
and data warehouses to and monitoring tasks using applications by using Python and develop security tools
enable efficient data Python scripts and tools like for automation and using Python.
analysis and reporting. Ansible and Docker. monitoring.
Script Wave

What is Python?
Python is a very popular general-purpose interpreted,
interactive, object-oriented, and high-level programming
language. Python is dynamically-typed and garbage-
collected programming language. It was created by
Guido van Rossum during 1985- 1990. Like Perl, Python
source code is also available under the GNU General
Public License (GPL).

Python supports multiple programming paradigms,


including Procedural, Object Oriented and
Functional programming language.

Page 5
SCTIPT WAVE

Features of Python

Easy Free High-Level


Open-Source

Portable Object-Oriented Large Standard Library Dynamically Typed

PYTHON ZERO TO HERO Slide 04


Script Wave

Why to Learn Python?


Python is Open Source which means it's available free of
cost.
Python is simple and so easy to learn.
Python is versatile and can be used to create many
different things.
Python has powerful development libraries including AI,
ML, etc.
Python is much in demand and ensures a high salary

Page 5
Script Wave

Environment set-up
In this course, we will be using Pycham as our code editor.
Steps for installation:

Page 5
Sript Wave

Working of python

Page 5
Script Wave

Commenting
Comments in Python are identified with a hash symbol, #, and
extend to the end of the line. Hash(#) characters in a string are
not considered comments, however. There are three ways to
write a comment - as a separate line, beside the corresponding
statement of code, or as a multi-line comment block.

Increasing readability
Explaining the code to others
Understanding the code easily after a long-term
Doc-strings
Re-using the existing code

Page 5
Script Wave

Code-Commenting

Page 5
Script Wave

Run Your first python code


Open IDLE using windows or mac

Click file new file and new file window pops up.

Now you start writing the code hello world

Ctrl/cmd + s (save) give a meaningful name and add .py


as extension.
In menu bar find run menu hit run(Module)

Page 5
Sript Wave

First Output

Page 5
SCRIPT WAVE

Output-function
The print() function prints the specified message to the screen or another
standard output device.
The message can be a string, or any other object, the object will be converted
into a string before written to the screen.
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

objects - object to the printed. * indicates that there may be more than one object
sep - objects are separated by sep. Default value: ' '
end - end is printed at last
file - must be an object with write(string) method. If omitted, sys.stdout will be used
which prints objects on the screen.
flush - If True, the stream is forcibly flushed. Default value: False

Page 5
Script Wave
Java Script

Variables PYTHON

Python Variable is containers that store values. Python is not


HTML5

“statically typed”. We do not need to declare variables or their


type before using them. A variable is created the moment we
first assign a value to it. A Python variable is a name given to a
memory location. It is the basic unit of storage in a program.

Page 5
Script Wave

Rules for Variables


A variable name must start with a letter or the underscore
character.
A variable name cannot start with a number.
A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ ).
Variable names are case-sensitive (name, Name and NAME
are three different variables).
The reserved words(keywords) cannot be used naming the
variable.

Page 5
Script Wave
Java Script

keyWords PYTHON

HTML5

Page 5
Script Wave

Quiz Time
From the following names mention which
are valid and invalid names
1. myvar = "John"
2. my_var = "John"
3. 2myvar = "John"
4. _my_var = "John"
5. myVar = "John"
6. my-var = "John"
7. MYVAR = "John"
8. continue = "John"
Script Wave

Quiz Time
From the following names mention which are valid and
invalid names
1. myvar = "John" Legal
2. my_var = "John" Legal
3. 2myvar = "John" Illegal
4. _my_var = "John" Legal
5. myVar = "John" Legal
6. my-var = "John" Illegal
7. MYVAR = "John" Legal
8. continue = "John" Illegal
Script Wave 2023

DATA
TYPES
Page 6
Coding School

DATA TYPES
Python Data Types are used to define the type of a
variable. It defines what type of data we are going to
store in a variable. The data stored in memory can be of
many types. For example, a person's age is stored as a
numeric value and his or her address is stored as
alphanumeric characters.
Note: In python we need not to declare any data types like
we do in C,C++,Java(int a=10;). we directly assign the value
when we need them
DATA TYPES Classification
Script Wave
2023

Data types

Numeric Boolean String Sequence

Int Float Complex List Float Set Dict

Page 6
Script Wave

Numeric
Number data types store numeric values. They are
immutable data types, which means that changing the
value of a number data type results in a newly allocated
object.
Numeric

Int Float Complex


Script Wave

Integer - Int
This value is represented by int class. It contains
positive or negative whole numbers (without
fraction or decimal). In Python there is no limit to
how long an integer value can be.

OUTPUT
CODE
Page 5
Script Wave

Float - float
This is a real number with floating-point representation.
It is specified by a decimal point.Optionally, the
character e or E followed by a positive or negative
integer may be appended to specify scientific notation.

OUTPUT
CODE
Scritp Wave

Complex - complex
A complex number is created from real numbers.
Python complex number can be created either using
direct assignment statement or by using complex ()
function.

OUTPUT
CODE
Script Wave

Strings
Strings in python are surrounded by either single
quotation marks, or double quotation marks.

Page 5
Script Wave

Strings
In Python, a string is a sequence of characters enclosed within single, double,
or triple quotes. Strings are one of the fundamental data types in Python and
are commonly used for text processing, manipulation, and storage.

Creating strings
You can create strings using single (' '), double (" "), or
triple (''' ''' or """ """) quotes. Examples:
Script Wave

Strings-Creationg code


Script Wave

String Indexing & sclicing


In Python, strings are ordered sequences of character data
and thus can be indexed in this way. Individual characters
in a string can be accessed by specifying the string name
followed by a number in square brackets ([]).

Positive Indexing 0 1 2 3 4 5

P Y T H O N
Negative Indexing -6 -5 -4 3 -2 -1
Script Wave

String Indexing - Code


Code:

Output:
Script Wave

String slicing
String slicing in Python is a fundamental operation that allows
you to extract a portion or substring from a string. It's a powerful
feature that's often used when working with text data.

Syntax:
substring = my_string[start_index:end_index:step]

OUTPUT
CODE 0 1 2 3 4 5

P Y T H O N
-6 -5 -4 3 -2 -1
Script Wave

Escape Sequence
Python Escape Sequence is a combination of
characters (usually prefixed with an escape
character), that has a non-literal character
interpretation such that, the character’s
sequences which are considered as an escape
sequence have a meaning other than the literal
characters contained therein.
Script Wave

Case Changing of Strings


The below Python functions are used to change the case of the strings.
Let’s look at some Python string methods with examples:

lower(): Converts all uppercase characters in a string into lowercase


upper(): Converts all lowercase characters in a string into uppercase
title(): Convert string to title case
swapcase(): Swap the cases of all characters in a string
capitalize(): Convert the first character of a string to uppercase

CLICK HERE FOR MORE


METHODS
Script Wave

Removing Spaces from the String:


1) rstrip() : To remove spaces at right hand side
2) lstrip() : To remove spaces at left hand side
3) strip() : To remove spaces both sides
Script Wave

Lists
Page 5
Script Wave

LISTS
Python Lists are just like dynamically sized arrays, declared in other
languages (vector in C++ and ArrayList in Java). In simple language, a
list is a collection of things, enclosed in [ ] and separated by commas.

CREATING A LIST IN PYTHON


Script Wave

ACCESSING ELEMENTS FROM THE LIST


In order to access the list items refer to the index number. Use the
index operator [ ] to access an item in a list. The index must be an
integer. Nested lists are accessed using nested indexing.
ACCESSING ELEMENTS FROM LIST
Script Wave

ACCESSING ELEMENTS FROM A


MULTI-DIMENSIONAL LIST
Script Wave

ADDING ELEMENTS TO A PYTHON LIST


append() extend() insert()
Script Wave

REMOVING ELEMENTS FROM THE LIST


remove() pop() Index()

Sort()
Script Wave

MATHS ON LIST
Addition [Concatenation] Multiplication
Script Wave

TUPLE
Python Tuple is a collection of
objects separated by commas. In
some ways, a tuple is similar to a
Python list in terms of indexing,
nested objects, and repetition but
the main difference between both is
Python tuple is immutable, unlike
the Python list which is mutable.
Script Wave

TUPLE PACKING AND UNPACKING


Tuple packing is when multiple values are assigned to a tuple without
using parentheses, while tuple unpacking is the reverse.

COUNT
Script Wave

ADDING ELEMENTS TO A PYTHON LIST


min() max()

sum()
Script Wave

LIST TUPLE

Lists are mutable Tuples are immutable

The implication of iterations is Time- The implication of iterations is


consuming comparatively Faster

The list is better for performing


A Tuple data type is appropriate for
THE
operations, such as insertion and
deletion.
accessing the elements
DIFFERENCE
Tuple consumes less memory as
Lists consume more memory
compared to the list

Tuple does not have many built-in


Lists have several built-in methods
methods.

Unexpected changes and errors are Because tuples don’t change they
more likely to occur are far less error-prone.
Script Wave

SET OPERATIONS
A set is a collection of unique
elements without any specific
order.
Script Wave

SET MATH OPERATIONS


Union Intersection

Difference Symmetric Difference


Script Wave

DICT ACCESSING
A dictionary in Python is an unordered
collection of items. Each item in a
dictionary is a key-value pair.

GET ALL KEYS & VALUES


Script Wave

DICT OPERATIONS
Create Update

Read Delete
Script Wave
OPERATORS 2023

Operators

Arthematic Comparision Assignment Logical Membership

Page 6
Script Wave 2023

Operators!
Script Wave

ARITHEMATIC OPERATORS
Operator Description Syntax

+ Addition: adds two operands x+y

– Subtraction: subtracts two operands x–y

* Multiplication: multiplies two operands x*y

/ Division (float): divides the first operand by the second x/y

// Division (floor): divides the first operand by the second x // y

Modulus: returns the remainder when the first operand is divided


% x%y
by the second

** Power (Exponent): Returns first raised to power second x ** y


Script Wave

ASSIGNMENT OPERATORS
Operator Description Syntax

= Assign value of right side of expression to left side operand x=y+z

Add and Assign: Add right side operand with left side operand and then assign
+= a += b
to left operand

Subtract AND: Subtract right operand from left operand and then assign to left
-= a -= b
operand: True if both operands are equal

Multiply AND: Multiply right operand with left operand and then assign to left
*= a *= b
operand

Divide AND: Divide left operand with right operand and then assign to left
/= a /= b
operand

Modulus AND: Takes modulus using left and right operands and assign result
%= a %= b
to left operand
Script Wave

COMPARISION OPERATORS

Operator Name Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal to x >= y

<= Less than or equal to x <= y


Script Wave

LOGICAL OPERATORS

OPERATOR DESCRIPTION SYNTAX Example

and Returns True if both the operands are true x and y x>7 and x>10

Returns True if either of the operands is


or x or y x<7 or x>15
true

not(x>7 and x>


not Returns True if the operand is false not x
10)
Script Wave 2023

Venu Prakash Reddy


Contact: 6302643093
email:
[email protected]

You might also like