{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Values & Types, Variables, Std I/O, Computations\n",
"- A value is one of the fundamental things -- like a letter or number -- that a program manipulates. \n",
"- These values are classified into data types.\n",
"\n",
"- In Python, there're mainly two data types: numbers and strings - numbers can be integer or float\n",
"- Boolean (True/False) is also supported type!\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## first program - hello world!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world!\n"
]
}
],
"source": [
"# First program\n",
"# This is a comment line...\n",
"# By Programmer info...\n",
"print('Hello world!')\n",
"# In python 2: print is a statement not a function\n",
"# print 'Hello World!' "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## comments\n",
"- Programming languages provide a way to write comment along with the codes\n",
"- Python uses # symbol to write a single line comment\n",
"- comments are for humans/programmers to convey/explain what the code is doing or supposed to do\n",
"- Python interpreter ignores the comments"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## data types\n",
"- built-in type() function can be used to know type of data\n",
"- functions will be covered in Chapter 04"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"int"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(100)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"float"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(1000.99)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type('Hello World!')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type('A')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "Missing parentheses in call to 'print'. Did you mean print(hello)? (
\n",
"1. Parenthesis\n",
"2. Exponentiation\n",
"3. Multiplication and Division (left to right)\n",
"4. Addition and Subtraction (left to right)\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"18\n"
]
}
],
"source": [
"# some examples\n",
"print(2 * 3 ** 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## operations on string\n",
"- Chapter 08 covers more on string data type"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on class str in module builtins:\n",
"\n",
"class str(object)\n",
" | str(object='') -> str\n",
" | str(bytes_or_buffer[, encoding[, errors]]) -> str\n",
" | \n",
" | Create a new string object from the given object. If encoding or\n",
" | errors is specified, then the object must expose a data buffer\n",
" | that will be decoded using the given encoding and error handler.\n",
" | Otherwise, returns the result of object.__str__() (if defined)\n",
" | or repr(object).\n",
" | encoding defaults to sys.getdefaultencoding().\n",
" | errors defaults to 'strict'.\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __add__(self, value, /)\n",
" | Return self+value.\n",
" | \n",
" | __contains__(self, key, /)\n",
" | Return key in self.\n",
" | \n",
" | __eq__(self, value, /)\n",
" | Return self==value.\n",
" | \n",
" | __format__(self, format_spec, /)\n",
" | Return a formatted version of the string as described by format_spec.\n",
" | \n",
" | __ge__(self, value, /)\n",
" | Return self>=value.\n",
" | \n",
" | __getattribute__(self, name, /)\n",
" | Return getattr(self, name).\n",
" | \n",
" | __getitem__(self, key, /)\n",
" | Return self[key].\n",
" | \n",
" | __getnewargs__(...)\n",
" | \n",
" | __gt__(self, value, /)\n",
" | Return self>value.\n",
" | \n",
" | __hash__(self, /)\n",
" | Return hash(self).\n",
" | \n",
" | __iter__(self, /)\n",
" | Implement iter(self).\n",
" | \n",
" | __le__(self, value, /)\n",
" | Return self<=value.\n",
" | \n",
" | __len__(self, /)\n",
" | Return len(self).\n",
" | \n",
" | __lt__(self, value, /)\n",
" | Return self