-
Notifications
You must be signed in to change notification settings - Fork 3
kb 17.py #10
Description
1 a. Create 5 variables that hold string
b. Get the last two characters from each string
c. Use 5 string methods to perform some string operations
name='kabiru'
age=15
school='alQalam'
state='katsina'
hobbies='chess'
name[-2:]
'ru'
school[2:4]
'Qa'
state[0:3]
'kat'
state[0:2]
'ka'
','.join('kabiru')
'k,a,b,i,r,u'
name.capitalize()
'Kabiru'
name.split()
['abubakar', 'kabiru']
name='KABIRU'
name.lower()
'kabiru'
2 Create 5 variables that hold integer
Use the following arithmetic operators to
perform some operations with the integers above:
+=, -=, /=, *=
number1=90
number2=40
number3=50
number4=10
number5=15
number1=90
number1 +=7
number1
97
number2=40
number2-=4
number2
36
number3=50
number3/=2
number3
25.0
number4=10
number4*=2
number4
20
3 a. Create 5 variables that hold list
b. Get the last two items from each list
c. Use 5 string methods to perform some list operations
name=['Abubakar']
state=['kaduna']
hobbies=['chess']
age=[15]
school=['auk']
name[-2:]
'ru'
school[2:4]
'Qa'
state[0:3]
'kat'
state[0:2]
'ka'
name
['Abubakar']
name.append('Kabir')
name
['Abubakar', 'Kabir']
name.reverse()
name
['Kabir', 'Abubakar']
name.pop(1)
'Abubakar'
name=['Kabir', 'usman', 'abubakar']
name.remove('usman')
name
['Kabir', 'abubakar']
name.clear()
name
[]
4 a. Create 5 variables that hold dictionary
b. Get the last two values from each dict
c. Use 5 dict methods to perform some dict operations
people={'name':'kabir'}
state={'state':'kaduna'}
school={'school':'auk'}
place={'Area':'Malali lowcost'}
people['name'][1:3]
'ab'
state['state'][-3:5]
'un'
school['school'][1:3]
'uk'
place['Area'][2:4]
'la'
place['Area'][2:4]+place['Area'][7:9]
'lalo'