Python Syntax Overview

# Hello World
print("Hello world")

# Functions
def main(): # define a function, call it main (by convention)
    print("Hello World")

if __name__ == "__main__":
    main()

# Conditionals
if x < y:
    print("x is less than y")
elif x > y:
    print("x is greater than y")
else:
    print("x is equal to y")

  • def define a function

-CS50 2017 - Lecture 8 - Python