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

Python Notes Part 1 1727438232

Python Notes

Uploaded by

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

Python Notes Part 1 1727438232

Python Notes

Uploaded by

Rutuja Pawar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

PYTHON - NOTES [Warun Kanike]

--------------------------------------------------------------------------------------------------------------------------
INTRODUCTION:
What is Python?

Python is a popular programming language. It was created by Guido Van Rossum and released on 20
Feb 1991.
Python is High Level Object Oriented Programming Language.

Python is used for:

 Web Development,
 Software Development,
 Data Analysis,
 System Scripting,
 Task Automation,
 Data Visualisation

--------------------------------------------------------------------------------------------------------------------------------------

Difference between Procedural Oriented Programming & Object Oriented Programming:

Procedural Oriented Programming Object Oriented Programming


The Programs are divided into small parts called The Programs are divided into small parts called
functions. objects.
There is no access specifier in procedural There are access specifier in Object-Oriented
programming programming like private, public, protected etc.
Adding new data and functions is not easy Adding new data and functions is easy
Overloading is not possible Overloading is possible
There is no concept of data hiding and There is concept of data hiding and inheritance
inheritance
It is used for designing medium-sized program It is used for designing large and complex
program
It uses the concept of procedure abstraction It uses the concept of data abstraction
Examples : C, FORTRAN, Pascal, etc. Examples : C++, Java, Python, C#, etc.

--------------------------------------------------------------------------------------------------------------------------------------

IDE – Integrated Development Environment for python are as follow:

 Jupyter Notebook
 PyCharm
 IDLE
 Visual Studio
 Spyder
VARIABLES IN PYTHON

Variables are containers for storing data values.


How to create a variable and how we can assign a value to it?

X = “Warun”, Y = 24, Z = [“Data Analyst”, 3]

Where X, Y, Z are variables.

In Python Indexing start from 0 i.e.


W = 0, a = 1, r = 2, u = 3, n = 4
--------------------------------------------------------------------------------------------------------------------------------------

BUILT – IN DATA TYPES

In programming, data type is an important concept.


Variables can store data of different types and different types has its own functionality.

Types Representation
Text str
Numeric int, float, complex
Sequence list, tuple, range
Mapping dict
Set set, frozenset
Boolean bool

Few Examples are listed below:

Data Types Examples


str x = “Hi there, this is Warun”
int x = 24
float x = 24.6
complex x = 12j
list x = [“Warun”, ”Data Cleaning”, ”Data Load”]
tuple x = (“Warun”, “ETL”, “Data Transform”)
range x = range(6)
dict x = {“Name” : “Warun”, “Age” : 24}
set x = {“Data Analyst”, “Data Scientist”}
frozenset x = frozenset({“friend”, “best friend”})
bool x = True

--------------------------------------------------------------------------------------------------------------------------------------
PYTHON STRINGS

Strings in python are surrounded by either single quotation or double quotation marks.
Eg: ‘Hello Python here’ or “Hello Python here”

Assign String to a Variable

Multiline String
You can assign a multiline string to a variable by using three single or double quotes

Strings as Arrays
Strings in Python are arrays. Square brackets can be used to access elements of the string.

String Length

Check String

--------------------------------------------------------------------------------------------------------------------------------------
SLICING
You can return a range of characters by using the slice syntax.
Specify the start index and the end index, separated by colon, to return a part of the string.

MODIFY STRINGS IN PYTHON

CONCATENATION

How to combine String and Number


We can combine String and Number by using the format() method.
The format() method takes the passed arguments, format them and place them in the string where
the placeholders {} are:
STRING METHODS

Method Description
capitalize() Converts the first character to upper case
count() Returns the number of times a specified value occurs in a string
endswith() Returns true if string ends with the specified value
find() Searches the string for a specified value and returns the position of
where it was found
format() Formats specified values in a string
index() Searches the string for a specified value and returns the position of
where it was found
isalnum() Returns True if all characters in the string are alphanumeric
isalpha() Returns True if all characters in the string are in the alphabet
islower() Returns True if all characters in the string are lower case
isnumeric() Returns True if all characters in the string are numeric
isspace() Returns True if all characters in the string are whitespaces
isupper() Returns True if all characters in the string are upper case
lower() Converts a string into lower case
replace() Returns a string where a specified value is replaced with a specified
value
split() Splits the string at the specified separator, and return a list
strip() Remove whitespace from start and end
swapcase() Swaps cases, lower case becomes upper case and vice versa
title() Converts the first character of each word into upper case
upper() Converts a string into upper case

--------------------------------------------------------------------------------------------------------------------------------------

BOOLEAN

You can evaluate any expression in Python and get one of two answers, True or False.
Almost any value is evaluated to True if it has some sort of content.
Any String is True, except empty strings.
Any number is True, except 0.
Any list, tuple, set and dictionary are True, except empty ones.
PYTHON OPERATORS

Operators are used to perform operations on variables and values.


Operators are as follows:
 Arithmetic Operators
 Assignment Operators
 Comparison Operators
 Logical Operators
 Identity Operators
 Membership Operators
 Bitwise Operators

ARITHMETIC OPERATORS

Operator Name Example


+ Addition x+y
- Subtraction x–y
* Multiplication x*y
/ Division x/y
% Modulus x%y
** Exponentiation x ** y
// Floor Division x // y

ASSIGNMENT OPERATORS

Operator Example Same As


= x=5 x=5
+= x += 7 x=x+7
-= x -= 8 x=x–8
*= x *= 3 x=x*3
/= x /= 14 x = x / 14
%= x %= 14 x = x % 14
//= x //= 14 x = x // 14
**= x **= 3 x = x ** 3
COMPARISON OPERATOR

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
LOGICAL OPERATOR

Operator Description Example


and Return True if both statements x < 5 and x > 3
are True
or Return True if one of the x < 5 or x > 3
statements is true
not Reverse the result, returns not(x < 5 and a < 10)
False if the result is true

IDENTITY OPERATOR

Operator Description Example


is Returns True if both variables x is y
are the same object
is not Return True if both variables x is not y
are not the same object
MEMBERSHIP OPERATOR

Operator Description Example


in Returns True if a sequence x in y
with the specified value is
present in the object
not in Returns True if a sequence x not in y
with the specified value is not
present in the object

BITWISE OPERATOR

Operator Name Description Example


& AND Sets each bit to 1 if both x&y
bits are 1
| OR Sets each bit to 1 if one x|y
of two bits is 1
^ XOR Sets each bit to 1 if only x^y
one of two bits is 1
~ NOT Inverts all the bits ~x

You might also like