Advertisement
liam4409

Untitled

Oct 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. numbers = [5,6,2,3,5,7,7,7,7,5,5,0]
  2. This list has a index of 0-11
  3. numbers.index(5)
  4. names = [liam, evan, amanda, megan]
  5. user = input("Please enter your name")
  6. " And".join(names)
  7. print("These are the coolest people in the world")
  8. if user == names:
  9. print("Then you're part of the squad")
  10. elif:
  11. print("Kys")
  12.  
  13. numbers[5:9]
  14. #This function will print out all the 7's that we have on this list
  15. #How to reverse a string or list
  16. "Reverse this sentence"
  17. string = "Reverse this sentence"
  18. string[::-1]
  19. #This will fully reverse any type of string or interger or object
  20. #Modifying portions of lists
  21. numberz = [1,2,3,4,5,6,7]
  22. numberz[1:3] = ["a","b","c"]
  23. print(numberz)
  24. #This will equal [1,"a","b","c",5,6,7]
  25.  
  26.  
  27. # DATA structures and matricies
  28. Nested_List
  29. nested_list = [[1,2,3], [4,5,6], [7,8,9]]
  30. #when accesing nested list you have to use the index of what you want to access then the index of the item you want to access
  31. nested_list[0][1]
  32. # Which in this case would equal the interger of 2 in the first list
  33. coords = [[10.20, 9.123], [40.20, 23.14], [85.12, 14.85]]
  34. for locations in coords:
  35. print(locations)
  36. #This will result in all brackets of coords to be printed
  37. for locations in coords:
  38. for coord in locations:
  39. print(coord)
  40.  
  41. [[i for i in range(0,10)] for num in range(0,10)]
  42. #Thats how you make a 2D array with the dimensions of 10x10
  43. How to make a dictionary
  44. cat = {"name": "Missy", "Age": 14, "Is_She_Cute": True}
  45. cat2 = dict(name="stinky bum", age=2, sexe="Female")
  46. #When trying to find specific data in a dictionary always remember to use the KEY
  47. User = {
  48. "name": "Liam",
  49. "Age": 20,
  50. "Weight": 205:
  51. "Favourite_Number": 44,
  52. "Goals": "To become a programmer",
  53. "Graduated": True,
  54. }
  55. for data in User.values():
  56. print(data)
  57. #Accessing all values in a Dictionary using the .values() function
  58. #You can do the same thing using the .keys() function which will print the keys of your dictionary
  59. for data in User.keys():
  60. print(data)
  61. #When trying to access all the data inside a dict aka the keys and the data use the .items() function and use two "VALUES" as seen in this example
  62. for key,data in User.items():
  63. print(f"key is{key} and data is{data}")
  64. #Made and F-STRING to string it all together and it will print out all the data and label it using the labels I put there
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement