Python Programming Lecture 2 PDF
Document Details
Uploaded by ResponsiveGermanium
2024
Dr. Mohammed Abdelfattah
Tags
Summary
This Python programming lecture provides an overview of key concepts, including operator precedence, syntax, and data types. The presentation offers examples and explanations of various Python elements. The material covers essential aspects of Python programming.
Full Transcript
Lecture 2 PROGRAMMING ESSENTIAL IN BY: D R. M O H AMMED A B D ELFAT TA H 2024 DR. MOHAMMED ABDELFATTAH 1 Lecture Objectives ❑ Review ❑ Multiple Statements ❑ Operator Precedence ❑ As...
Lecture 2 PROGRAMMING ESSENTIAL IN BY: D R. M O H AMMED A B D ELFAT TA H 2024 DR. MOHAMMED ABDELFATTAH 1 Lecture Objectives ❑ Review ❑ Multiple Statements ❑ Operator Precedence ❑ Assigning Values to Variables ❑ Basic Syntax ❑ Multiple Assignment ❑ Storing Variable ❑ Standard Data Types ❑ Python Identifiers ❑ Data Type Conversion ❑ Reserved Words ❑ Arithmetic Operators ❑ Lines and Indentation ❑ Comparison Operators ❑ Multi-Line Statements ❑ Assignment Operators ❑ Quotation in Python ❑ Logical Operators ❑ Comments in Python ❑ User Input 2024 DR. MOHAMMED ABDELFATTAH 2 Operator Precedence 1. Parenthesis () 2. Exponentiation ^ 3. Multiplication/Division * / 4. Addition/Subtraction + - 2024 DR. MOHAMMED ABDELFATTAH 3 Operations Hierarchy Example 3 * (6 + 2) / 12 – (7 – 5) ^ 2 * 3 () first = 3 * 8 / 12 – 2 ^ 2 * 3 ^ next = 3 * 8 / 12 – 4 * 3 Mult / Div (L to R) = 24 / 12 – 4 * 3 Mult / Div (L to R) = 2 – 12 Add / Subtr = -10 2024 DR. MOHAMMED ABDELFATTAH 4 Basic Syntax If you are running new version of Python, then you would need to use print statement with parenthesis as in print ("Hello, Python!"); However in Python version 2.4.3. >>> print "Hello, Python!" >>> print ("Hello, Python! ") 2024 DR. MOHAMMED ABDELFATTAH 5 Storing Variable Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. Based on the data type of a variable, the interpreter allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals or characters in these variables. 2024 DR. MOHAMMED ABDELFATTAH 6 Storing Variable 2024 DR. MOHAMMED ABDELFATTAH 7 Python Identifiers A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9). Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language. Thus, Manpower and manpower are two different identifiers in Python. 2024 DR. MOHAMMED ABDELFATTAH 8 Reserved Words and exec not The following list shows the Python keywords. assert finally or These are reserved words and you cannot use break for pass them as constant or variable or any other class from print identifier names. continue global raise def if return del import try elif in while All the Python keywords contain lowercase else is with letters only. except lambda yield 2024 DR. MOHAMMED ABDELFATTAH 9 Lines and Indentation Python provides no braces to indicate Void main() blocks of code for class and function { definitions or flow control. string Name="Ali"; cout