Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- def my_ip():
- print('my ip address is 10.1.1.1')
- #calling the function
- my_ip()
- def print_my_ip_address(ip_addr):
- print('my address is {}'.format(ip_addr))
- return
- print_my_ip_address('192.1.1.1')
- #mapping the argument positionally
- def print_my_cred(ip_addr,username,passwd):
- print('my address is {}'.format(ip_addr))
- print('my username is {}'.format(username))
- print('my password is {}'.format(passwd))
- return
- print_my_cred('192.1.1.1','tosin','amazon')
- #named argument
- print('*'*50)
- def print_my_cred(ip_addr,username,passwd):
- print('my address is {}'.format(ip_addr))
- print('my username is {}'.format(username))
- print('my password is {}'.format(passwd))
- return
- print_my_cred(ip_addr='192.1.1.1',passwd='tosin',username='amazon')
- #mixing positional argument with named argument: we have to specify all the positional argument first before name
- print_my_cred('192.1.1.1','tosin',passwd='amazon')
- #using default value
- print('*'*50)
- def print_my_cred_default(ip_addr,username='aramide',passwd='cisco123'):
- print('my address is {}'.format(ip_addr))
- print('my username is {}'.format(username))
- print('my password is {}'.format(passwd))
- return
- print_my_cred_default('200.20.1.10')
- print_my_cred_default('200.20.1.10','tosin',passwd='amazon')
- #using list to parse argument
- my_list=['200.100.1.1','tosin','cisco123']
- my_dic={'ip_addr':'300.1.1.1',
- 'username':'aramideo',
- 'passwd':'cisco456'
- }
- print('*'*50)
- def print_my_cred_list(ip_addr,username='aramide',passwd='cisco123'):
- print('my address is {}'.format(ip_addr))
- print('my username is {}'.format(username))
- print('my password is {}'.format(passwd))
- return
- #to pass it as a sequence of value we need to put * in front of it
- print_my_cred_list(*my_list)
- # ** convert the dic into the argument
- print_my_cred_list(**my_dic)
- print('*'*50)
- ip_addr2='100.1.1.1'
- def print_my_cred_local(ip_addr,username='aramide',passwd='cisco123'):
- ip_addr2='30.30.30'
- print('my address is {}'.format(ip_addr))
- print('my username is {}'.format(username))
- print('my password is {}'.format(passwd))
- print('my address is {}'.format(ip_addr2))
- return
- print_my_cred_local('200.20.1.10')
- class MYclass(object):
- def __init__ (self,ip_addr,username,password:)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement