Python Basics Week 1
Python Basics Week 1
Example:
print (3 + 4) # integer addition - output 7
print (3.5 + 4.5) # float addition - output 8.0
print(13 / 2) # / division operator - output 6.5
print(13 // 2) # floor operator - discards the decimal part – output 6
print(13 % 2) # remainder (modulo) operator - returns the remainder
of the division – output 1
ARITHMETIC EXPRESSION
Fundamentals of Python:
First Programs
PRECEDENCE RULES
Precedence rules:
• ** has the highest precedence and is evaluated first
• Unary negation is evaluated next
• *, /, and % are evaluated before + and -
• + and - are evaluated before =
• With two exceptions, operations of equal precedence are
left associative, so they are evaluated from left to right
• ** and = are right associative
• You can use () to change the order of evaluation
Fundamentals of Python:
First Programs
EXPRESSION EVALUATION
Fundamentals of Python:
First Programs
VARIABLES
To store information or data and then work with them later, you need
to know exact location of the memory where data is stored.
Example:
Go to Week 1 PDF_CODE
STRING
Example:
print (" My First Program")
My First Program
My First Program
My First Class
Go to Week 1 PDF_CODE
LISTS
Example 1
array1 = [ 1, 3, 5, 7, 9]
print(array1) # output- [1, 3, 5, 7, 9]
Fundamentals of Python:
11
First Programs
CONTROL FLOW STATEMENT - IF
Go to Week 1 PDF_CODE
Thank You
No tutorial in this week