0% found this document useful (0 votes)
2 views24 pages

Python Notes

The document provides an overview of clean coding practices using Python, covering basic concepts such as variables, data types, and operators. It includes examples of code syntax, comments, and tips for writing clean and efficient code. Additionally, it discusses various Python data structures like lists, tuples, and dictionaries, along with their characteristics and usage.

Uploaded by

kvbarkakana1177
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)
2 views24 pages

Python Notes

The document provides an overview of clean coding practices using Python, covering basic concepts such as variables, data types, and operators. It includes examples of code syntax, comments, and tips for writing clean and efficient code. Additionally, it discusses various Python data structures like lists, tuples, and dictionaries, along with their characteristics and usage.

Uploaded by

kvbarkakana1177
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

Clean coding

with

Python

From :-31/08/23
Till : -

Semester :
-

Sen-1

Professor : -

Karan Sir
LIBN expert
once y
Python with

Basics about
py t h o n

: -

-is our
first

print ("Hello World'


program
If to frogramconvert the
with

we evere ehis
save- -

"Hello py" ! first this


name .

Python would
The
follo byte
ode
fell fanzoy-own it
&
·

or sher .

at should half

Hello Pymfile" Hello


·
·
PXL-7
Python virtual
zuschine

Ourcompiler code ble to


source
our
conver t

:

byte coole After which inside python's


&

it
critual machine &

/definitions : -

-> information
collects e
fe
file
multiple

from
:

- &

I facter -Interfector
median

for
: communication
is
the

between multiple collected/compiled inform nation


ments Comments :
-

are

data
non-compiled
string
-- is

of .
It often
used to explain how the

code is
femilioning
<- etc .

The
single-line comment syntax is -

for multiline comment


,
the syntes is-"Hi""
13 double quotes)

Creating a variable :
A variable is
basically
holds
object
an

value :
that a defined

It is a part of the

OOPS (Object-Oriented Programming system)


To name/declare a variable ,
do-variable-1 = "H :

There are certain limitations to names of a variable .

Acceptable numing parameters


-

I characters -
(a-2)

1 Integen-Lannot start with integers)


③-(underscore)-(cannot start with double underscore

The variable declaration system is a

naming
sensitive
sys te m

case .
Some clean
Coding Tips s Tricks

⑨ You san declare multiple variables values in a

single line of code,

For ex c
,
b, c = 1 , 2 , 3

e
-m
print (a ,
b, L)- Output ->

123

b You can also do calculations inside of a

paint avoid declaring another variable


statement to

it
or
function

for
for ex : -

x= wrong way x = 1
V
1

2
R y
y
I
/
=
=

2 = x +

y perint(u+y) I
Output correct
-

front (2)-autlaut -> 3



way
3

I To find out the


tyke of a variable , we

use a tyke function


for example :
- k
=

43
print (take (n)) -outfout -> Dictionary"
osconi
Python
with

types :

① text
type -> Str

② Numeric type-> Int , float , complex

③ Sequence type-> List ,


Tupl Range
,

④ Mapping type- Dictionary


③ set type-> Set , frozen set
⑥ Bookan
tibe- Boo

⑦ Binary tyke-Byte Bytearray , , memory view

⑧ Move type More ->

n-Variable data
tigpen

containing
:

comple numbers .

Ex : -x =
1 j

-I
2) List Sequence bayed data containing
t y ke

different data tykes


.

Ordered
i]
·

Eg :
-n =

[ 10 ,
Hi ,
·

chargable
·

Duplicatable
: Basically list but
-
read -

only .

Orderen
(10 78)
·

Hi
eg
: -

, , ·

Duplicatable
·

changable

-
4) Range : -

Usel to
whole
get
numbers
sequence of
.
Not

compatible

with decimals .

10) -> Outbut -


Eg :
x=
rany(P
-

print (w) range (0 10) ,

So I key-based tionary
:
-
data take
Eg :
-GName' :
"Karan' ,
"Rank' :
Professor's
·
ordered

·
key-based data
·

key must be
unique ,
However data doesnt require uniquenes .
Eatykes : -

-
⑰ Set Unorganised
: -
set of data

I
Unordered
example
·
: -

Unchangable
GName's
·

Karan' ,
"Rank ,
Professor's
·
Unindexed

duplicate
No
e
·

& Frozen sets


:
-

example : -

(Name's Karan' ,
"Ranks ,
Professor']
11/09/23

tykes
Des : -

Byte I
:
Byte-Bing form
-

of data .

A
=

bKARAN convert to binary

&array-Arranged data
binning

form of .

eg
:- B =
bytway [1-]

I my pic

Operators ⑦ operators
-
Sothetic
:

② Assignment operators
③ Comparison operators

④ Logical operators

⑤ Bit-wise operator

⑥ dentity
I
I operator

⑦ Membership operator syllabus


Arithmetic Operators : -

I addition (H)

I subtraction 2-3

3) Multifly( *
)
Division(/)

⑤ Floor division(/1)

6 Modulus (%)

I Exponential ( **)

I Assignment operators :

Simple , operator &

used lo
-

assign

variabl value ·
ER :
-

A =
"H :

All assignment operators :-

I =
I
x = 1 137 =

I
x =
x -
71

I t = x 1 12) x ny S
=

x +
=
.

I S

3) - x 1 13) x
=
xAS
=

x -

I I

⑭Y * I
n
=
xx1

I G x
=

x/z
I

6 1 I
n
=

x117

1)
=

* * 3
a x ** k

0
1 x
= x =
1
S

I
- I
x = x)1

= x
=

x I
I
-Simbre
3) Comparision compare values
we
operators : -

1 --
I
4
=

= S (Oufurt-False) (Bodean)
I I I 2 : 3 (Outbut-True)
=

3 - I

I
-3
5>3

? E
14 1
=

27 = z
S

~ Logical operators : -

I) AND
,
x < =
20 AND Y <= 21

2) OR A 10 OR B 1
=
=

>

3) NOT
String
12109123

tination
-

A =
"Hello Output -> HelloWorld
B = "World'

print (A +

String Format .

Age 30
Age
=

30

text :
'My age is E3
text -

"My age is

point [text + Age) paint [text


format

(Age))

Freos
I
, string + Integer The right
is
logically invorent

for kythos
&
3/09/23

case
-
types
comel east

my-Name-Is

) Pascal ease

My-Name-Is
③ Smoke case

my-name- is

-> Unpacking
collection
a

A =

71' ,
2,
]
X Y Z , ,
= A

Putbut -> As a result , the values of X


,
Y, have

X = I

y = 'z
z =
-
15/09123
Chan Coding
-

& Write
The san of
a
program
first

n
:-

natural members is given by the formula


*
San =
IN [N+13]
given a no . N=S

Find of first fine natural no


the

sin a
.

My You
R
are given 4 members A ,
B
,
C
,
B
, find

the average of the 4 numbers

D .

You are even members A B,


: C , D ,
I in the

*
expression (A B)
+ (( -B) /t

& Indice is scoing at a rem


per over .
How many ou

will indi score in 30 over


assiming
the eve Rate

remains the sun during the sp overs

as
given

a member o
, find its cube
.

GD) You have given radius is of the cricle


you have to

find the beaiites and the


op
circle

area
⑰ Given a quadratic expression , +2x+1 . Now

find the value of 2 When =


M ut
("Fr definevalue)
& You are
given
,
4 numbers stored is 4 variables A , B, C , D .

Print the

result of A> B
>B

⑭ You are given integers A , B, L .


Find wether they
or able to form equilater
&

a tangle .

Print yes
or wo

Qi Given 3
integer A, B, < and
find

the maximum of the


Sentegers
18/09/23

ing/sliving
Indessing
-
: -

slicing
-
: -

H
A = "Hello
↑y +↑
print (AC0]) ->

01234-Inden values
Joint (A[ s]) -> :

on sin

Gint (A( S]) : -> Hello


-
Start to
indenn-1 specified

faint (A(2 -> ello :

Negative Slicing :
-

A= Hello
↑y +↑
01234
S
- -

4-7-2 -
1

fint(A(-s -1]) :
Negative slizing can
:
only foint

upte-1 indes potlon it


↓output
comot

point the last position

Hell

(AES ])
point
use to till 0
foint
:

op

Hello
fully
we can also use multiple slice operations in one line .

,
Ey point ([1 thats ellable
: s
: :
1

List
I As
list
items ⑤ look list a) Joint list

2) change list items ⑯list comprehension D List methods

③ Add
list
items ③ Sort list

I Remove items Coby list


l i st
Finish n o te s

of

19/09/23
20/09/23

fies
Tuples
-
-

D Oytha tuples
2)
tuple

Acco
3) update taple
I impassed tuple
look
tuple

jo Tuftech e
22109/23
Lists
-

Copy lists -12 : =

I' ,
'B'
, "21] ,
12 =23

to
coby ,
dont do I instead do this -

12 21 Lz
[Link]()
=

X V

list
Join : There are 2 built-in functions ,

Inland
Adding
13 =
L2+ 22 23 =
11 enterd (L2)

List methods :

Basically built-in function of list


data type

ples
Defined/created by-

Tc ('A' $ ,)
'
=
;

T1 =
tuble (PA ,
'B' , (1)

Accen items : -

sand as list

print [+1 2037


Updating tuple : -T2 =
('A' ; : ,)

11 =

list (T2) -> 11 ·

abherd (D)

T =
tuble (L1 coby) .

Unpacking tuples : - Tc= ('A' ,


B ,)

X , Y , z
=

T2

print X) A
!
->
->
fint YS B

fart (2) - <

Joint table
: -

Ts = T1 +

I2

Multiplying of tuples :
-

Is= T1
*
2

forint (T1) = ABCABL


26/09/23

Dictionary
Topics :
-

I Introduction to dictionary 1) look methods


2) add ) Copy dictionary
items

Change items 0) Nested dictionary


⑰ Remove items a) dictionary metho

3) access itams

Introduction to

dictionary :
-

D1='Mane' :
"Karan' , 'Class : B .

Tech's
Defining
bracket Blu markers
keys
represent

Green marker represents data linked to keys ,

Insert all like (2) etc


list
still
.

Access items :
- x =

D1 [Mame']

frint (a) -> "Karan

OR
use D1 ·

get (Name")
To get all beys ,
use De Reys() function

fint (De kays()


. -> ('Mane' "Class']
,

To yet all values , use D2 .

Values () function

frint (D1 values()) -- L'Kar' ,


'B .

Ters']
Finish mote of becaus
thuschen A Friday
-
-
som
conditions if statements

You might also like