Tuesday, October 30, 2018

Python Data Types.

Python has various different data types. 
Let's take a look at some of them.

1. Strings (str):  This could be any character surround via by a single or double quote. state = "California"
2. Integer (int): zip=92129
3. Float (float):  latitude=34.073620
4. Boolean (bool): True or false You_Rich=True
5. List (list): Value can be of any data type in a [].   home =["Beverly Hills", "Mansion", "Penthouse"]
6. Dictionary  list of key value pairs in a {}.  phone_contact ={"John": "555-5555", "Gina": "555-5252", "Lisa": "555-5255"}
7. Set (set): Collection of unique elements. set(vendors)=>['att', 'verizon', 'tcox']
8 Tuple: (tuple) Immutable sequence of values (): address=(10, 10, 20, 20)

Immutable in python = You can't change the value.
Other types such as Strings, List, Dictionary are all mutable.  You can change these values .
Example of immutable values such as social security #.  You are assigned one social security #.  That value will never change.  You can change your name but your SSN will be the same.


Determining types.
type(name of variable)

Example:
>>> state = "California"
>>> type(state)
<class 'str'>

>>> type(zip)
<class 'int'>

>>> type(latitude)
<class 'float'>

Python operators
Python has the different operators which allows you to carry out required calculations in your program.
python operators
+  , -  and *  works as expected, remaining operators require some explanation.
similarly you can use -  , %  , //  , /  , *  , **  with assignment operator to form augmented assignment operator.
python augmented assignment operators
Source: https://thepythonguru.com/python-numbers/
Great Video to watch regarding Data Types.

Sunday, October 28, 2018

Python Basic Variables

Basic Variables in Python.

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.


Learning Python and installing it on windows.

I'm on a mission to learn Python!!  Just my daily log so I can keep my self motivate to learn python coding and keep at it.

Why do I want to learn python?
So I can automate the boring stuff and learn something new!

What version am I going to learn?
Python 3.

Installation:
Download Python from offical website.
https://www.python.org/downloads/


Since I don't have another PC I will install it on my existing windows machine.
Setup the Window System variable.

https://docs.python.org/3/using/windows.html

3.1.2. Installation Steps

Four Python 3.7 installers are available for download - two each for the 32-bit and 64-bit versions of the interpreter. The web installer is a small initial download, and it will automatically download the required components as necessary. The offline installer includes the components necessary for a default installation and only requires an internet connection for optional features. See Installing Without Downloading for other ways to avoid downloading during installation.
After starting the installer, one of two options may be selected:
../_images/win_installer.png
If you select “Install Now”:
  • You will not need to be an administrator (unless a system update for the C Runtime Library is required or you install the Python Launcher for Windows for all users)
  • Python will be installed into your user directory
  • The Python Launcher for Windows will be installed according to the option at the bottom of the first page
  • The standard library, test suite, launcher and pip will be installed
  • If selected, the install directory will be added to your PATH
  • Shortcuts will only be visible for the current user
Selecting “Customize installation” will allow you to select the features to install, the installation location and other options or post-install actions. To install debugging symbols or binaries, you will need to use this option.
To perform an all-users installation, you should select “Customize installation”. In this case:
  • You may be required to provide administrative credentials or approval
  • Python will be installed into the Program Files directory
  • The Python Launcher for Windows will be installed into the Windows directory
  • Optional features may be selected during installation
  • The standard library can be pre-compiled to bytecode
  • If selected, the install directory will be added to the system PATH
  • Shortcuts are available for all users
4. Need help watch Video