Advertisement
TopFloorSolutions

Python Introduction

Oct 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # Michael Borchardt
  3. # Python Introduction
  4.  
  5. # Data Types
  6. # --> int && str
  7.  
  8. # Syntax: object reference = value
  9. _str1 = 'i am string'
  10. _str2 = "i am string also"
  11. _int1 = len(_str1)
  12.  
  13. print(_str1, len(_str2[::6]), _int1)
  14.  
  15. if(len(_str2[::6]) >= 3):
  16.     print('monkeys rule the world')
  17. else:
  18.     print('no, those are republicans')
  19.  
  20.  
  21. # Changing an immutable object.
  22. _str1 = 'you are not a string'
  23.  
  24. # Data Type Conversions
  25. print(_str1)
  26. print(str(45))
  27.  
  28. # Tuples: Immutable collections of object references -- cannot be changed once created.
  29. _tup1 = ('1','2','3')
  30. print(_tup1)
  31.  
  32. # Collecting objects of multiple data types (e.g. str/int)
  33. _tup2 = ('alpha',1,'bravo',2,'charlie',3)
  34. print(_tup2)
  35. print(type(_tup2))
  36. print(len(_tup2))
  37.  
  38. # Lists: Mutable collections of object references -- can be changed once created.
  39. _list1 = ['alpha', 1, 'bravo', 2, 'charlie',3]
  40. print(_list1)
  41. print(type(_list1))
  42. print(len(_list1))
  43.  
  44. # List Function: Append
  45. _list1.append('delta')
  46. _list1.append(4)
  47. print(_list1)
  48.  
  49. # Specify the data type and the data types method, pass in additional arguments.
  50. list.append(_list1, 'echo')
  51. list.append(_list1, 5)
  52. print(_list1)
  53.  
  54. # Calling an object reference from a certain position in the list.
  55. print(_list1[0], _list1[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement