Advertisement
Abahbob

example00.py

Jan 23rd, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. '''
  2. Some notes:
  3.     Anything within triple apostrophes, or following a '#' is a comment. This won't be ran.
  4.     Python relies on tabulation to determine code flow.
  5.         If a line is tabbed and the previous isn't, then it is typically reliant on the previous line.
  6.         Other languages handle it with brackets, such as
  7.             if (x == y) {
  8.                 print("X is equal to Y");
  9.             }
  10.         In python, you don't use brackets, but it can be easier to think with them.
  11.     When a python file is opened (via the python command, or from another python file), it automatically runs anything that is not indented.
  12.         Lines beginning with 'def' are functions, so they are only ran if explicitly called.
  13.         Lines beginning with 'import' are using other files or modules.
  14. '''
  15.  
  16. def foo(): #This is a function. It does things
  17.     bar = "Hello" #This is a varible. This one holds a string.
  18.     fizz = 1 #This is also a varible. This one holds an integer.
  19.     buzz = None #This is another variable. This one doesn't have anything in it yet.
  20.     if bar == "Hello": #This is a conditional statement. If the statement is true, continue to the indented code. Otherwise, jump past it.
  21.         print("Bar is equal to \"Hello\"")
  22.     else: #If the conditional is false, we run the else. The else statement is optional
  23.         print("Bar is not equal to \"Hello\"") #The '\' character here says that the quotations are part of the string, as opposed to closing it.
  24.  
  25. print("Running example00.py") #This will always print when you run the file
  26. if __name__ == '__main__': #This checks to make sure that you ran "python example00.py", as opposed to always running it. It's not too important right now.
  27.     foo() #Calls the foo function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement