Python 1
Python 1
Presentation on Python
Science – Bioinformatics (It is a filed which uses computer software tools for understanding
biological data)
Web application Development
Testing scripts
System administration
Who uses python today…
Add: +
Subtract: -
Divide: /
Multiply: *
print 3 + 12 >> 15
print 12 – 3 >> 9
print 12 + 3 -7 + 5 >> 13
print 3 * 12 >> 36
print 12.0/3.0 >> 4.0
print 2 < 3 True
print 2 != 3 True
Data type..
String - “Hello”
Integer – 24
Float – 3.1415
List [“a”, “b”, “c”]
Python can tell the data type using type() function:
>>> print type(“Hello”)
Output – type ‘str”
Strings in python
Output - 5
Looping..
Python If..Else
The elif keyword is pythons way of saying "if the previous conditions were not true, then try
this condition".
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Output - a and b are equal
Else
The else keyword catches anything which isn't caught by the preceding conditions.
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Output - a is greater than b
We can also have an else without the elif :
a = 200
b = 33
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a
set, or a string).
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
Output - apple
banana
cherry
Looping Through a String
Output –
b
a
n
a
n
a
The break Statement
With the break statement we can stop the loop before it has looped through all the items:
Exit the loop when x is “banana”:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
Output –
apple
banana
Thank You!