Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- #Use of main function
- def main():
- #Strings
- x = "hello"
- x = 'hello' #' and " do the same thing
- x = """hello my\nname is\ntamsen""" #"""creates multiple line string, \n is a new line
- #https://www.programiz.com/python-programming/methods/string <-- methods
- #Creating Variables
- x = True #bool
- x = False
- x = 1 #int
- x = 1.1 #float
- x = "hello" #string
- x = [1, 2, 3] #list
- #variables' types can change
- #http://developer.rhino3d.com/guides/rhinopython/python-datatypes/ <-- more in depth
- #user input
- name = input("what is your name?")
- number = input("type a number")
- number = int(number) #input() takes in everything as a string so you have to convert it if you want a dif. type
- #you can do things like int(var), bool(var), float(var), etc to convert
- #For loops (various ways to do it), each prints 3 times
- for i in range(3):
- print("hello")
- for i in range(1,4):
- print("bonjour")
- for i in range(1,7,2):
- print("hallo")
- #range explanation: https://www.pythoncentral.io/pythons-range-function-explained/
- for i in [1, 2, 3]:
- print("hola")
- #Lists
- x = [1, 2, 3]
- y = x[0] #indexes are the same as they are in java
- y = x[-1] #-1 is the end of a list (going left from 0)
- #Turtle Class (import statement at the top of the module)
- #https://docs.python.org/3.3/library/turtle.html?highlight=turtle <-- documentation w/ methods
- wn = turtle.Screen()
- t = turtle.Turtle()
- #^^ always need these two methods at the beginning 3(names are changeable tho)
- wn.exitonclick() #end turtle programs with this
- #Converting from integer to binary to List
- x = 5
- print(bin(x)) #x goes from 5 to 0b101 (which is a string). the 0b represent that it's in binary, and the 101 is 5 in binary
- print(bin(x)[2:]) #to get rid of the 0b
- y = bin(x)[2:]
- y = list(y) #turns 101 into a list where each number is one index - ['1', '0', '1']
- print(y)
- #creating functions
- def hello():
- print("hello")
- hello()
- if __name__ == "__main__": #runs the main function. fun fact idk how it works so don't ask me
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement