Python Basic Syntax
Python is an interpreted programming language, this means that as a developer you write Python (.py
) programs in a text editor and use the Python interpreter to execute it directly by using either one of the following two commands, where “HelloWorld.py
” is the name of your Python program:
shell> /usr/bin/python HelloWorld.py
shell> python HelloWorld.py
|
A Python program can be built as follows:
- Sign in to the server “
undcemcs02.und.edu
,” and navigate to the directory where you want to save your Python program.
- Write the first Python program, called
HelloWorld.py
, which can be done in any text editor.
- Execute the program.
shell> cat HelloWorld.py
print "Hello, World!"
shell> python HelloWorld.py
Hello, World!
|
Python Comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #, and Python will render the rest of the line as a comment.
Python Variables
Variables are containers for storing data values.
In Python, variables are created when you assign a value to it.
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
shell> cat Test.py
x = 4 # x is of type int.
x = "Sally" # x is now of type str.
print( x )
shell> python Test.py
Sally
|
Maybe if we tell people the brain is an app,
they’ll start using it.
|