0% found this document useful (0 votes)
4 views5 pages

Python Notes

Uploaded by

st2sw8hjm7
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)
4 views5 pages

Python Notes

Uploaded by

st2sw8hjm7
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/ 5

Python Note

Data
types :

1 .
int >
-

.
2 float >
-
1.
3
.
string >* -

4 .
boolean > True/False
-

O
. Condition

Conditions only have two


possible outcome/values : True or False
Et often involves () (
operators << = = = = !=

e 5 1= 6 >
- True
.
g
.

13 25 >
- False

3 = = 4 >
-
False
.

Conditions are most likely to be used in If statements and while


loop
if of
Apple 0 == :
e .
g
. num

print ("out of stock")

Note that data could be involved the


any types in comparing
.
e
.
g
.

"Hello world
"
Hello World" == >
- true

Advanced level :

Boolean car be used directly as a condition


.

Which is intuitive the outcome of condition is boolean (True/false)


very as
Chapter
-
-
. 1
Introduction to
programming
shares lot similarities
Programming a with
building Lega Programmers
a .
uses

different the
components in order to achieve results
they wanted
.

here fundermental
are some
components :

1 .
If else statement

It handle different to different conditions.


can and execute
operations according

Structure :
indition
elifestation :

action
else :

Action

2 . for Loop
It creates an
loop for a fixed and given amount of timeliteration
.

where will the code the


it
performs inside
lep over and over
again.

e.
g .
for i in
range
(0 , 3) :

(str(i)
print

Output : 0 12

variable Which
"

Note that the variable" ; in this context is a


.
means its value could

change and can be replaced by other letters.

Advanced level : Nested for


lop

It's a for loop inside another for loop . Just like the movie Inception.
for i in (0 3) :
e
g .: range ,
.

for ; in
range (0 ,
4) :

print (i ,
j

Note that the 2nd iteration of the first for leep (i) will only begin after
the last iteration of the second for
loop (j)
times
which
implies the code above should 12 run
in total
= N for loop (XI) runy , -A for loop run ni ,

/I for loop runi R


= : 1st for loop run &EiR ,

E* run 3x4 =
12 a

While
3 .
loop

fulfilled
It create a
loop that will
keep running forever until given condition is

While
structure : datin

C .
G
. While is-raining ==
True :

use Umbrella

Array
-

A list contains different values (Pfdata type B -1 ·


+2 Store

Index : Data Stel) Il


eg .

List :
12/0741-5/9/100
Index : 0 1 2 3 4 5

How to declare the list above :

list -
1 =
[ 12 , 0 ,
4 , -5 , 9 ,
100]
**** -
E program List XGREEEP X 2 :

list. 1 = [ 12 , 0
,
4 ,
-
5 ,
9
,
100]

for i in
range
(o , 6) :

#
list [[i]-
= list 1ti] - 2

print (list - 1)

Output : [24, 0
,
8 , -10 , 18 , 2007

Exercise :

Write that1st Declare list same as the mentioned above


program .
a a one

2:"Reverse the +re/-ve(-1 >


-
1
,
15 + -
15)
3rd Print the reversed list

line1 :

line 2 :

line3 :

You might also like