Print List Operations and Methods
Print List Operations and Methods
1"A"]
,
new- list (1 2)
empty-list + +
age e
=
(15 ,
35
,
10] -
eX1 eX2
his
(1 2 3)
Repetition Opr
num1
=
, n = 10
listons
,
2 .
(41 :
n nume" num1 ** zeros = 10]
*
n
print(num) print(zeros
: list n [ 1 2
, ,
% ,
7 2 3
, , ,
1 4
, ,
%] 10 ,
0 0 0 0 0 0 0 0
, , , , , , ,
0
,
eX1 eX2
(17 45]
Philist
IDS =
40 %77
IDS [11 93]
(Checking Opr) meanor in Var
20
, ,
777
: ,
3 in : , , ,
user ID -
:
int (input ('Enter w's
User ID1 :
20
if
-
user-ID in JDS :
varis an en
IDr
syntax
=
77
print c'Yes'
user .
lis + 1 < 1 5 7 9]
n :
int input en : 's
, ,
list
,
list
1 item []
=
i in rangens :
print clists
1101 Var gun des)
listi Appende is
list 1 Appende item (
.
Stax
:
(1 5 7 9
, ,
77] print clists
, ,
2 .
Insert methods (lon items indexin (11 ,
2
,
3, 41) Insert (150) .
·ninazera
!
3 .
Remove methods Inwa item Woman listinvitin (111 , e 33 , ,
14 222) . remove cre
,
& Sort
.
methods (long min-max) (17 ,
3 ,
0 2
,
,
51) .
Sort
syntax
: list sorts ( (2 3, 4 , 5, 7]
w ,
,
ex
Delete :
del seg1[I]
no item any index
print (segi) [11 ,]
del sege [i]
printssegt) (17)
Useful built-in function * Flem : En
1. sumclists =
Minniznessiglist e .
g .
sum( (1 ,
2 3
, ,
12) 10
. max clists :
Mansonialist e .
g .
max (13 7 2 , , ,
11) 7
· . minclists =
Mahainatalist e .
g min (13 7
.
, ,
2
,
11)
1 .
Copy by append : e .
Copy by +
list 1 = <7 2 B 4]
, , ,
list 1 = [1 2 3 4)
,, ,
&
list 2 append c item
&D List : List now list (neetwlist inte Int) : : list <it (j)
ex list : ((1 ,
2
,
19 ,
12)
print(listcos) (1 2)
,
print clisticosis e
print clisticislos) a
item :
Bakinwania iterable
interable -
list2 (inmoni
UC
118 Oct .
2024] Destinen
Syntax
nu
: def function- name (optional parameters) :
Statement
Statement
exc :
functionmin printe
2 function Tatian
def print. name
.
is :
3 .
mings enginee
: Prnfunction print "Alice" o Not output
print("Hello, names
,
namee
say-hellose''Alice' ,
namee - Bob's Hello Alice Bob
·
I minion ta function]
calce ,
b) by Emenia
def gen-charc :
verwin
"Hello)
output gen-chase ·
·
return values Valuez Values
, ,
·
antia 1 .
mineisiksin nat ex def multiples :
2 .
Nig , asiksin an In Tuple return 1 2 3
, ,
X
,y
print
,
2
(x,
:
y
multipless
,
2) 0123
you
&
outputs : muliples
(b)
print (output says
of
: Manis
def print-welcome) :
(1) (2)
print, 'Welcome ' ..
print :'This is ..
'I
X =
int(input(s)
y
=
int (input()
return (xtysle
def main es :
print- Welcome
cal
ang argis
=
-
Missis
①
function inolenitenes
Library
importnew importlibrarynaesion
(see
names
1 .
11 random , seedlines a ser mini ninnclimsien
es math (numwim &miner's import math
function
2 1) math sin(x) math re math sareesox ; X is radian 10-24)
.
.
.
expex) .
2 .
2) math. e
3 1415
.
math .
pi
3) I def returne :
return 1
,
2,
1) X, y , 2 "
1 2 3
, ,
01
(1 NOV 2024] Infunction same list unis append/insert 2) tup =
1, 2
,
3 0 (1, 2
,
3)
stringSequencii a
target-'T'
a
target chars
:
& my-string
= 'Hello There'
! for char in
my- string
:
print chars t
print (name (i)
print (counts -4
name str
2 O end 1
Slicing-winstring + Str/start :
stop :
steps aie
rangecisions tops & list index
10
print 3) -
(str(3 :
aminer iAs
1 is alnums-oiconais or wiring
2 is alphas-oicons
is
digitis =
wiring
& .
is lowers =
mension
5 .
is upper-risingstan ! * check me string slicing I
6 is spaces =esins ,
Esseningi
zig19
S
Creating new
string methods (return a new string
& ex :
my-str
'Abc
=
.
.
uppers) -
return new
string invision stonege print ( new. str) o abe
.
~strips) =
. stripes :
nwng nins
-
.
Stripc'char's :
an snasmin s e zane
find (substring)
·
=
m index was
substring (index of char) ,
miss output--
ex :
Str =
Heltette'
new str :
Str .
replace C'e 'O'
,
print (new-strs
"
ex :
my-str
=
"ABCD ef of
Ist-my-strsplit ? "
"
infor list
string operators
*: "ab" ** - "ababab"
+: "ab"t'ed" w "abea"
" ,
,"
-
3 C x
&
folder
inmonistringAnythin
-
work ns a
dict-werowing in key
&
value
w
Accessing Value
,
dict <key
syntax
:
print (my-dict (A1) -
print (my-dict(c)s -a
print (mydicts o
I'd' : 1
,
'B' :
2
,
'c'ib}
value
anything mydict-["Anna" ,"Bob" "Hello" "Mary" 1 3) I
11 -
31 :
,
2 : :
2
,
, ,
,
in query
if query in dict :
"fah" False
my-dictin print (dic +
-
(query
Creating an
empty
dict Can be
#
ingate empty dict
se dict l neimsien Fritz
=
wite dict elists
my-dict-[} empty dict e EFati
on
student : : 10
,
names : I'Fahl ,
'Oue']
student 23
my-dict" Bob "
=
=
2
for i in
rangeden names :
for key
dicplooping loop makey ! in dict
ex mydict
=
(Alice' 'Beb' : ,
n
, 'Mary : key 'Alice' :
,
Value -
1
,
:
2
print of 'Key =
&key 3 ,
Value :
[my-dict(keys' Fey 'Mary' :
,
Value :
keycs :
reture all key in list !I d. keyses
·
Value is :
reture all Value 18 list ! Id .
values
, ,
e fruits
:
L'Apple' 'Apple' , Banana' , Banana' , Orange' Banana']
, , e his in Brows ten :
fruit-dict =
93 loop 1 :
Apple (Not in Fruit dict +1 sentences : "This is a cat meow meow meow cat "
get ,
- n e
print (world-dicts
Nested dic
, gender' ''grade :Al 'b' :Age
Value Value
List of dict
Isi : / l'Alice' 13 :
,
EBob' 15 :
,
[Anna' :
3/