abobaker09

Sequence_into_Separate_Variables_python

Oct 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #تفكيك المتغيرات الي تسلسلات مختلفة
  2. s=[1,2,3]
  3. a,b,c=s   #هنا تحصل عملية تفكيك بحيث اي عنصر هياخذ قيمه معينه
  4. print(a)
  5. print(b)
  6. print(c)
  7. g="abobaker"
  8. a,b,c,d,e,f,k,h=g
  9. print(a)
  10. print(b)
  11. print(c)
  12. print(d)
  13. print(e)
  14. print(f)
  15. print(k)
  16. print(h)
  17. k=["beko","hlal","mohaemd"]
  18. g,h,j=k
  19. print(g)
  20. print(h)
  21. print(j)
  22. #مثال اخر
  23. y=(7,8,6,5,4)
  24. a,b,*c=y  #يستخدم الموشر * لكي  يدل علي ان المتغير يمكنه ان يخزن عدة قيم
  25. print(a)
  26. print(b)
  27. print(c)
  28.  
  29. print("____________________________________")
  30. ########################
  31. records = [
  32.  
  33.  ('foo', 1, 2),
  34.  
  35.  ('bar', 'hello'),
  36.  
  37.  ('foo', 3, 4),
  38.  
  39. ]
  40.  
  41. def do_foo(x, y):
  42.  
  43.      print('foo', x, y)
  44.  
  45. def do_bar(s):
  46.  
  47.      print('bar', s)
  48.  
  49. for tag, *args in records:
  50.  
  51.      if tag == 'foo':
  52.  
  53.         do_foo(*args)
  54.  
  55.      elif tag == 'bar':
  56.  
  57.          do_bar(*args)
Advertisement
Add Comment
Please, Sign In to add comment