Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """This is what a python script looks like."""
- # Importing modules and packages
- # Normal import
- import math
- # Import namespace
- import math as psychology
- # Import specific component.
- from math import sin
- # Script
- # Define a function
- def func(*args):
- # Notice no brackets. Indent takes place of brackets.
- # Conditionals
- if True:
- pass
- elif False:
- pass
- else:
- pass
- # Notice lack of semicolons to end statements. Newlines do that
- # Loops
- # for loop
- for i in range(10):
- # do something
- else:
- # Finish up
- # Foreach loop
- arr = ["camel", "baby", "seagull"]
- for item in arr:
- # print to console
- print("This is a {}".format(item))
- # While loop
- while True:
- break
- # Get input
- a = input("This text will be the prompt. ")
- return a
- # Define class
- class Mine:
- # Constructor
- def __init__(self):
- pass
- #Other methods
- def a_method(self):
- pass
- # Run as a script rather than a module to import from
- if __name__ == '__main__':
- # Call function
- func()
- # Instantiate class
- mine = Mine()
- # Call methods
- mine.a_method()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement