Advertisement
Dido09

Python - Tuples

Nov 2nd, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. # string to tuple
  2. my_string = input('Enter a string: ')
  3. tup1 = tuple(my_string)
  4. print(tup1)
  5.  
  6. # string to list (tup1)
  7. s1 = list(my_string)
  8. print(s1)
  9.  
  10. # prints list in reverse
  11. s2 = []
  12. for i in range(len(s1)):
  13. s2.append(s1[-(i+1)])
  14. print(s2)
  15.  
  16. # string to list (tup2)
  17. tup2 = tuple(s2)
  18. print(tup2)
  19.  
  20. # finds the number value of element
  21. s3 = []
  22. for i in range(len(s1)):
  23. s3.append(ord(s1[i]))
  24. print(s3)
  25. tup3 = tuple(s3)
  26. print(tup3)
  27.  
  28.  
  29. # sorts elements from smallest to largest
  30. s3.sort()
  31. print(s3)
  32. tup4 = tuple(s3)
  33. print(tup4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement