wa12rior

29.10.2019 Python

Oct 29th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. >>> wyraz = "Python!"
  2. >>> for znak in wyraz:
  3.     print(znak)
  4.  
  5.    
  6. P
  7. y
  8. t
  9. h
  10. o
  11. n
  12. !
  13. >>> wyrazy = ['python', 'kot', 'komputer']
  14. >>> for wyraz in wyrazy:
  15.     print(wyraz)
  16. ######################################
  17.    
  18. python
  19. kot
  20. komputer
  21.  
  22. >>> for wyraz in wyrazy:
  23.     print(wyraz, len(wyraz))
  24.  
  25.    
  26. python 6
  27. kot 3
  28. komputer 8
  29. >>> for i in range(5):
  30.     print(i)
  31.  
  32.    
  33. 0
  34. 1
  35. 2
  36. 3
  37. 4
  38. >>> for i in wyraz[1:3]:
  39.     print(i)
  40.  
  41. ######################################
  42. >>> list()
  43. []
  44. >>> a = list()
  45. >>> list('Python')
  46. ['P', 'y', 't', 'h', 'o', 'n']
  47. >>> list(range(10))
  48. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  49.  
  50. ######################################
  51.  
  52. >>> a = [34, 3232, 12]
  53. >>> sum(a)
  54. 3278
  55. >>> sum(range(-98,100,2))
  56.  
  57. ######################################
  58. # wypisuje liczby Fibonacciego
  59.  
  60. # 1, 1, 2, 3, 5, 8
  61.  
  62. x, y, i = 0, 1, 1
  63.  
  64. while i <= 10:
  65.     print(y)
  66.     x, y = y, x+y
  67.     i += 1
  68.  
  69. ########################################
  70.  
  71. x, y, i = 0, 1, 1
  72.  
  73. for i in range(10):
  74.     print(y)
  75.     x, y = y, x+y
  76.  
  77. #######################################
  78. wyrazy = ['Python', 'kot', 'komputer', 'pies']
  79.  
  80. for i in range(len(wyrazy)):
  81.     print(i ,wyrazy[i])
  82.  
  83. ### lub ###
  84.  
  85. for i, wyraz in enumerate(wyrazy):
  86.     print(i, wyraz)
  87.  
  88. ## albo ##
  89.  
  90. for i, wyraz in enumerate(wyrazy, start=1):
  91.     print(i, wyraz)
Add Comment
Please, Sign In to add comment