Braces? Semicolons? Meh.
# Example
def main():
print ("Hello World!")
You guessed it! '#' comments out the rest of line
# Example
def main(): # this is the main function
print ("Hello World!") # this prints Hello World!
Unlike the command-line interpreter, you need to print to see it!
# Example
def main():
a = 1
b = 2
a + b ## this will not be printed
c = a + b
print ( "The result is", c )
print ( a,b,c )
print ("Hello World!")
# undefine a variable in real time
del c
Everything is object in python!
We'll cover this later...
Can it run on its own? Sure it can.
#!/usr/local/bin/python3
def main():
print ("Hello World!")
if __name__ == "__main__":
main()
## make sure you change the file to be executable in shell.
## % chmod +x hw.py
No comments:
Post a Comment