Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- numbers = [5,6,2,3,5,7,7,7,7,5,5,0]
- This list has a index of 0-11
- numbers.index(5)
- names = [liam, evan, amanda, megan]
- user = input("Please enter your name")
- " And".join(names)
- print("These are the coolest people in the world")
- if user == names:
- print("Then you're part of the squad")
- elif:
- print("Kys")
- numbers[5:9]
- #This function will print out all the 7's that we have on this list
- #How to reverse a string or list
- "Reverse this sentence"
- string = "Reverse this sentence"
- string[::-1]
- #This will fully reverse any type of string or interger or object
- #Modifying portions of lists
- numberz = [1,2,3,4,5,6,7]
- numberz[1:3] = ["a","b","c"]
- print(numberz)
- #This will equal [1,"a","b","c",5,6,7]
- # DATA structures and matricies
- Nested_List
- nested_list = [[1,2,3], [4,5,6], [7,8,9]]
- #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
- nested_list[0][1]
- # Which in this case would equal the interger of 2 in the first list
- coords = [[10.20, 9.123], [40.20, 23.14], [85.12, 14.85]]
- for locations in coords:
- print(locations)
- #This will result in all brackets of coords to be printed
- for locations in coords:
- for coord in locations:
- print(coord)
- [[i for i in range(0,10)] for num in range(0,10)]
- #Thats how you make a 2D array with the dimensions of 10x10
- How to make a dictionary
- cat = {"name": "Missy", "Age": 14, "Is_She_Cute": True}
- cat2 = dict(name="stinky bum", age=2, sexe="Female")
- #When trying to find specific data in a dictionary always remember to use the KEY
- User = {
- "name": "Liam",
- "Age": 20,
- "Weight": 205:
- "Favourite_Number": 44,
- "Goals": "To become a programmer",
- "Graduated": True,
- }
- for data in User.values():
- print(data)
- #Accessing all values in a Dictionary using the .values() function
- #You can do the same thing using the .keys() function which will print the keys of your dictionary
- for data in User.keys():
- print(data)
- #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
- for key,data in User.items():
- print(f"key is{key} and data is{data}")
- #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