What is a Variable? It's a value you assign in python code to reference a value to a variable.
Take a look at the sample below.
Examples below.
Examples:
>>> hostname = 'home1'
>>> print(hostname)
home1
## This example above assign home1 to the variable hostname.
>>> pi = 3.14159
>>> print(pi)
3.14159
## This example above assign 3.14159 to variable name pi.
>>> banner = "\n\n Welcome home master! \n\n"
>>> print(banner)
Welcome home master!
>>>
## The example above assign Welcome home master! to the variable banner.
Using print interprets the "\n" and a new line is print statement only not within the Python terminal.
>>> banner
'\n\n Welcome home master! \n\n'
>>>
See the different above. If you call banner it will spit out the actual \n value from the variable banner.
Stick with either single quote or double quote. You can not mix and match them when you assign variables.
Example:
hostname = 'home1"
OR
hostname ="home1'
>>> hostname = 'home1"
SyntaxError: EOL while scanning string literal
>>>
Python doesn't like it when you use it together in the same line.
Stick with a single quote or a double quote.
Other site with good reference on Variables:
http://interactivepython.org/runestone/static/CS152f17/SimplePythonData/Variables.html
CJ Dojo has a nice intro video take a look.
No comments:
Post a Comment