Python Programming Lecture Notes PDF
Document Details
Uploaded by EliteCarnelian3565
Tags
Summary
This document is a set of lecture notes on Python programming, covering concepts like programming languages (interpreted vs. compiled), getting started with Jupyter Notebook. It includes examples and exercises.
Full Transcript
Two hour session each week SI-leaders: Flipe Eduardo Valle Quiroz ([email protected]) , group 1, TAITE Rajesh Rajan ([email protected]) , group 2, TAEIS + Erasmus Course Ambassador We follow the course ambassador model Survery is done...
Two hour session each week SI-leaders: Flipe Eduardo Valle Quiroz ([email protected]) , group 1, TAITE Rajesh Rajan ([email protected]) , group 2, TAEIS + Erasmus Course Ambassador We follow the course ambassador model Survery is done at the end of the course to evaluate it Course ambassadors help evaluating the course Any candidates for course ambassador? Programming Languages Low vs. High level High level languages are more Understandable by Humans Examples: C/C++, Java, Python, Go, TypeScript, Julia Low level languages are closer to machine (zeros and ones) x86 Assembly, ARM Assembly Interpreted vs. Compiled Compiled languages are first converted to binary executables and then run Examples: C/C++, Java, C#, Kotlin, Swift Interpreted languages are converted to binary line by line and executed Examples: JavaScript, Python Programming Languages General vs. Targeted Targeted languages are made for a specific kind of applications Examples: SQL for databases, HTML for web design, etc. General puprpose languages can be used for a wide range of applications Examples: C/C++, Python, Java, Swift, JavaScript In this course we focus on Python 3 which is an interpreted, high-level, general purpose programming language Python, one of the top programming languages Getting Started Installing Python There are many ways For this course Anaconda is recommended Go to https://www.anaconda.com/download/success Download and Run the Installer Running Python There are three different ways to run python Python Shell (IPython): Commands are typed line-by-line and the result is printed after each line Running Python File (script file):.py files are executed via the python in command prompt or terminal Using Jupyter Notebook: A notebook environment is opened in your web browser. Your commands are written in cells and executed via the notebook. In this course we mainly use Jupyter Notebook Jupyter Notebook Jupyter is installed within Anaconda Running a notebook: Open Jupyter Notebook or type "jupyter notebook" in Anaconda Prompt (Windows) or Terminal (macOS) Then click on New > Python 3 (ipykernel) The environement will open for you Jupyter Notebook Jupyter Notebook Demo Jupyter Notebook Your program is written in cells Each cell contains one unit of your program Type your porgram in a cell and then press shift + enter to run it To make a new cell press the + button in the toolbar Cells share memory: When running one cell you can use the variables defined in previously-run cells Python Programing A Python Program is a series of commands which are normally called statements A very simple python command: print() In : print("hello world") hello world Python Objects Objects: Core things that can be manipulated Scalar Object types: int, float, bool, none Non-scalar Object types: any other type Scalar Objects: int type means an integer: 1, 8, 386, etc. float type means a floating point (decimal) number: 1.1, 3.14, 0.00002 bool type can have values of True or False None type has a single value (similar to null in C/C++) Python Expressions Python Expressions are a combination of operators and objects All expressions have a value Example: 4+4 The value of this expression is: 8 To see an expressions value put it in a jupyter cell and press shift+enter: In : 4+4 Out: 8 Python Expressions You can make expression using the normal arithmetic operators (+ , - , / , *) In : 3+8 Out: 11 In : 5-10 Out: -5 In : 3*8 Out: 24 In : 4/0.1 Out: 40.0 Python Expressions Some other arithmetic operators are floor of division "//", remainder of division "%", and power "**" In : 3//2 Out: 1 In : 5%3 Out: 2 In : 2**4 Out: 16 Python Expressions To compare two objects to see if they are equal use "==" and if they are not equal use the "!=" operators This type of expression is a boolean expression In : 2==2 Out: True In : 5==3 Out: False In : 5!=3 Out: True Python Expressions Other comparative operators are >, =, 4 and 34 or 34 and 3