Lab - Week 7 (Yeni)
Lab - Week 7 (Yeni)
#lists
print(list('cat'))
lst1 = ['physics', 'chemistry', 2017, 2023]
print("Value available at index 2 : ", lst1[2])
#tuples
a_tuple = ('ready', 'fire', 'aim')
print(list(a_tuple))
tup1 = ('physics', 'chemistry', 2017, 2023)
tup2 = (1, 2, 3, 4, 5, 6, 7 )
print("tup1[3]: ", tup1[3])
print("tup2[2:6]: ", tup2[2:6])
2) Consider following statements about lists and tuples. See the results.
#deletion
mylist = ['python', 'java', 2017, 2023]
print(mylist)
del mylist[1]
print("After deleting value at index 1 : ", mylist)
#updating
lst2 = ['python', 'geometry', 2017, 2023]
print("Value available at index 3 : ", lst2[3])
lst2[3] = 5000
print("New value available at index 3 : ", lst2[3])
3) Consider following example and see the results.
#split
txt = 'but soft what light in yonder window breaks'
words = txt.split()
print(words)
#Two expressions
pow2 = [2 ** x for x in range(10) if x > 5]
print(pow2)
pow2 = []
for x in range(10):
pow2.append(2 ** x)
print(pow2)
4) Consider following statements by using functions for different goals. See the
results.
#accessing
L = ['a', 'b', 'c']
for index, item in enumerate(L):
print(index, item)
#concatenation
hello = "hello"
python = "python"
#slicing
ss = "Shark attacks fisherman!"
print(ss[:5])
print(ss[7:])
print(ss[-4:-1])
print(ss[0:12:2])
6) Consider following statements by using functions for different goals. See the
results.
#isalpha()
mystr1 = "this" #No space and digit in this string
print(mystr1.isalpha())
#isspace()
mystr5 = " "
print(mystr5.isspace())
7) Consider following statements by using functions for different goals. See the
results.
#strip()
print(mystr7.strip( '0' ))
#lstrip()
mystr8 = " this is string example....wow!!! "
print(mystr8.lstrip())
mystr9 = "88888888this is string example....wow!!!8888888"
print(mystr9.lstrip('8'))
#rstrip()
print(mystr10.rstrip())
print(mystr11.rstrip('8'))
8) Consider following statements by using functions for different goals. See the
results.
# endswith()
mystr12 = "this is string example....wow!!!"
suffix = "wow!!!"
print(mystr12.endswith(suffix))
print(mystr12.endswith(suffix,20))
suffix = "is"
print(mystr12.endswith(suffix, 2, 4))
print(mystr12.endswith(suffix, 2, 6))
#startswith()
mystr13 = "this is string example....wow!!!"
print(mystr13.startswith( 'this' ))
print(mystr13.startswith( 'is', 2, 4 ))
print(mystr13.startswith( 'this', 2, 4 ))