Advertisement
aramideoluwatosin

my_funtion.py

May 4th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. def my_ip():
  4. print('my ip address is 10.1.1.1')
  5.  
  6. #calling the function
  7. my_ip()
  8.  
  9.  
  10. def print_my_ip_address(ip_addr):
  11. print('my address is {}'.format(ip_addr))
  12. return
  13. print_my_ip_address('192.1.1.1')
  14.  
  15. #mapping the argument positionally
  16. def print_my_cred(ip_addr,username,passwd):
  17. print('my address is {}'.format(ip_addr))
  18. print('my username is {}'.format(username))
  19. print('my password is {}'.format(passwd))
  20. return
  21. print_my_cred('192.1.1.1','tosin','amazon')
  22.  
  23.  
  24. #named argument
  25. print('*'*50)
  26. def print_my_cred(ip_addr,username,passwd):
  27. print('my address is {}'.format(ip_addr))
  28. print('my username is {}'.format(username))
  29. print('my password is {}'.format(passwd))
  30. return
  31. print_my_cred(ip_addr='192.1.1.1',passwd='tosin',username='amazon')
  32.  
  33. #mixing positional argument with named argument: we have to specify all the positional argument first before name
  34. print_my_cred('192.1.1.1','tosin',passwd='amazon')
  35.  
  36.  
  37.  
  38. #using default value
  39. print('*'*50)
  40. def print_my_cred_default(ip_addr,username='aramide',passwd='cisco123'):
  41. print('my address is {}'.format(ip_addr))
  42. print('my username is {}'.format(username))
  43. print('my password is {}'.format(passwd))
  44. return
  45.  
  46. print_my_cred_default('200.20.1.10')
  47. print_my_cred_default('200.20.1.10','tosin',passwd='amazon')
  48.  
  49. #using list to parse argument
  50. my_list=['200.100.1.1','tosin','cisco123']
  51. my_dic={'ip_addr':'300.1.1.1',
  52. 'username':'aramideo',
  53. 'passwd':'cisco456'
  54. }
  55. print('*'*50)
  56. def print_my_cred_list(ip_addr,username='aramide',passwd='cisco123'):
  57. print('my address is {}'.format(ip_addr))
  58. print('my username is {}'.format(username))
  59. print('my password is {}'.format(passwd))
  60. return
  61. #to pass it as a sequence of value we need to put * in front of it
  62. print_my_cred_list(*my_list)
  63. # ** convert the dic into the argument
  64. print_my_cred_list(**my_dic)
  65.  
  66. print('*'*50)
  67. ip_addr2='100.1.1.1'
  68. def print_my_cred_local(ip_addr,username='aramide',passwd='cisco123'):
  69. ip_addr2='30.30.30'
  70. print('my address is {}'.format(ip_addr))
  71. print('my username is {}'.format(username))
  72. print('my password is {}'.format(passwd))
  73. print('my address is {}'.format(ip_addr2))
  74. return
  75.  
  76. print_my_cred_local('200.20.1.10')
  77.  
  78.  
  79. class MYclass(object):
  80. def __init__ (self,ip_addr,username,password:)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement