{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<small><small><i>\n",
    "All the IPython Notebooks in **Python Introduction** lecture series by **[Dr. Milaan Parmar](https://www.linkedin.com/in/milaanparmar/)** are available @ **[GitHub](https://github.com/milaan9/01_Python_Introduction)**\n",
    "</i></small></small>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python Hello, World\n",
    "\n",
    "**Python** is easy to learn and code and can be execute with python **interpreter**. We can also use Python **interactive shell** to test python code immediately. A simple hello world example is given below. Write below code in a file and save with **.py** extension. Python source file has **.pyextension**. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "### Writing the “Hello, World!” Program\n",
    "\n",
    "Now that we have Python up and running, we can write our first Python program.\n",
    "\n",
    "Let's create a very simple program called **`Hello World`**. A \"**Hello, World!**\" is a simple program that outputs **`Hello, World!`** on the screen. Since it's a very simple program, it's often used to introduce a new programming language to beginners.\n",
    "\n",
    "```python\n",
    "print(\"Hello, World!\")\n",
    "```\n",
    "\n",
    "Congratulations! You just wrote your first program in Python.\n",
    "\n",
    "As you can see, this was a pretty easy task. This is the beauty of Python programming language."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "heading_collapsed": true
   },
   "source": [
    "### Let’s break down the different components of the code.\n",
    "\n",
    "1. **`print()`** is a function that tells the computer to perform an action. We know it is a function because it uses parentheses. print() tells Python to display or output whatever we put in the parentheses. By default, this will output to the current terminal window.\n",
    "\n",
    "2. Some functions, like the **[print()](https://github.com/milaan9/04_Python_Functions/blob/main/002_Python_Functions_Built_in/051_Python_print%28%29.ipynb)** function, are **[built-in functions](https://github.com/milaan9/04_Python_Functions/tree/main/002_Python_Functions_Built_in)** included in Python by default. These built-in functions are always available for us to use in programs that we create. We can also define **our own functions** that we construct ourselves through other elements.\n",
    "\n",
    "3. Inside the parentheses of the **`print()`** function is a sequence of characters — **Hello, World!** — that is enclosed in quotation marks **`'`** or **`\"`**. Any characters that are inside of quotation marks are called a **string**.\n",
    "\n",
    "4. Once we are done writing our program, **save** the file and we can exit notepad.\n",
    "\n",
    "Once you exit out of notpad you’ll return to your shell or cmd.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Running the “Hello, World!” Program\n",
    "\n",
    "The hello.py program that you just created will cause your terminal to produce the following output:\n",
    "\n",
    "```python\n",
    "Hello, World!\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:05.446620Z",
     "start_time": "2021-10-02T05:54:05.428063Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello, World!\n"
     ]
    }
   ],
   "source": [
    "print(\"Hello, World!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Congratulations!** You have written the “Hello, World!” program in **Python 3**.\n",
    "Since the program ran, you can now confirm that **Python 3** is properly installed and that the program is **syntactically correct**."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### How to print blank lines\n",
    "\n",
    "Sometimes you need to print one blank line in your Python program. Following are an example to perform this task.\n",
    "\n",
    "#### Example:\n",
    "\n",
    "Let us print 8 blank lines. You can type:\n",
    "\n",
    "```python\n",
    ">>>print (9 * \"\\n\")\n",
    "```\n",
    "or\n",
    "\n",
    "```python\n",
    ">>>print (\"\\n\\n\\n\\n\\n\\n\\n\\n\\n\")\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:05.600914Z",
     "start_time": "2021-10-02T05:54:05.450525Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "Hello World!\n"
     ]
    }
   ],
   "source": [
    "print (\"Hello World!\")\n",
    "print (9 * \"\\n\")\n",
    "print (\"Hello World!\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:05.756188Z",
     "start_time": "2021-10-02T05:54:05.604821Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jan\n",
      "Feb\n",
      "Mar\n",
      "Apr\n",
      "May\n",
      "Jun\n",
      "Jul\n",
      "Aug\n",
      "Sep\n",
      "Oct\n",
      "Nov\n",
      "Dec\n"
     ]
    }
   ],
   "source": [
    "print (\"Jan\\nFeb\\nMar\\nApr\\nMay\\nJun\\nJul\\nAug\\nSep\\nOct\\nNov\\nDec\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:05.924154Z",
     "start_time": "2021-10-02T05:54:05.762046Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I want \\n to be printed.\n",
      "I'm very *happy*\n"
     ]
    }
   ],
   "source": [
    "print (\"I want \\\\n to be printed.\")\n",
    "print(\"I'm very *happy*\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.062828Z",
     "start_time": "2021-10-02T05:54:05.929039Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello\tWorld!\n"
     ]
    }
   ],
   "source": [
    "print (\"Hello\\tWorld!\") # \\t is equal to 4 spaces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.187828Z",
     "start_time": "2021-10-02T05:54:06.066736Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Routine:\n",
      "\t- Eat\n",
      "\t- Study\n",
      "\t- Sleep\n",
      "\t- Repeat\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print (\"\"\"\n",
    "Routine:\n",
    "\\t- Eat\n",
    "\\t- Study\n",
    "\\t- Sleep\\n\\t- Repeat\n",
    "\"\"\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Print end command\n",
    "\n",
    "By default, python's **`print()`** function ends with a newline. This function comes with a parameter called **`end`**. The default value of this parameter is **`\\n`**, i.e., the new line character. You can end a print statement with any character or string using this parameter. This is available in only in **Python 3+**\n",
    "\n",
    "#### Example 1:\n",
    "\n",
    "```python\n",
    ">>>print (\"Welcome to\", end = ' ') \n",
    ">>>print (\"Python\", end = '!')`\n",
    "\n",
    "Welcome to Python!\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.309901Z",
     "start_time": "2021-10-02T05:54:06.200522Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Welcome to Python!"
     ]
    }
   ],
   "source": [
    "print (\"Welcome to\", end = ' ') \n",
    "print (\"Python\", end = '!')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Example 2:\n",
    "\n",
    "```python\n",
    ">>>print(\"Python\" , end = '@')\n",
    "\n",
    "Python@\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.417317Z",
     "start_time": "2021-10-02T05:54:06.315757Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Python @"
     ]
    }
   ],
   "source": [
    "print(\"Python \" , end = '@') # ends the output with '@'."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.540364Z",
     "start_time": "2021-10-02T05:54:06.422203Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "_M_M_M_M_M_M_M_M_M\n"
     ]
    }
   ],
   "source": [
    "print ('_M'*9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-02T05:54:06.663900Z",
     "start_time": "2021-10-02T05:54:06.543296Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Hello Hello Hello Hello Hello \n"
     ]
    }
   ],
   "source": [
    "print(\"Hello \" * 6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}