Advertisement
Guest User

python syntax example

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. """This is what a python script looks like."""
  2. # Importing modules and packages
  3. # Normal import
  4. import math
  5. # Import namespace
  6. import math as psychology
  7. # Import specific component.
  8. from math import sin
  9.  
  10. # Script
  11. # Define a function
  12. def func(*args):
  13.     # Notice no brackets. Indent takes place of brackets.
  14.     # Conditionals
  15.     if True:
  16.         pass
  17.     elif False:
  18.         pass
  19.     else:
  20.         pass
  21.     # Notice lack of semicolons to end statements. Newlines do that
  22.     # Loops
  23.     # for loop
  24.     for i in range(10):
  25.         # do something
  26.     else:
  27.         # Finish up
  28.     # Foreach loop
  29.     arr = ["camel", "baby", "seagull"]
  30.     for item in arr:
  31.         # print to console
  32.         print("This is a {}".format(item))
  33.     # While loop
  34.     while True:
  35.         break
  36.     # Get input
  37.     a = input("This text will be the prompt. ")
  38.     return a
  39.  
  40. # Define class
  41. class Mine:
  42.     # Constructor
  43.     def __init__(self):
  44.         pass
  45.     #Other methods
  46.     def a_method(self):
  47.         pass
  48.    
  49. # Run as a script rather than a module to import from
  50. if __name__ == '__main__':
  51.     # Call function
  52.     func()
  53.     # Instantiate class
  54.     mine = Mine()
  55.     # Call methods
  56.     mine.a_method()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement