SlideShare a Scribd company logo
1 of 47
‫استاد‬:ُ‫زاد‬ ‫اهام‬ ‫هحود‬
‫درس‬:ِ‫هقده‬‫هحاسباتی‬ ‫سیاالت‬ ‫بر‬ ‫ای‬
‫دٍم‬ ‫ًیوسال‬94-95
‫ّریس‬ ُ‫زاد‬ ‫کاظن‬ ‫پَریا‬
910284261
•1982–1991‫رٍسَم‬ ‫في‬ ٍ‫گَید‬
•‫عٌَاى‬ ‫با‬ ‫اًگلستاى‬ ‫تَلید‬ ‫کودی‬ ‫سریال‬Monty Python’s Flying Circus
‫از‬1969‫تا‬1974ِ‫شبک‬ ‫از‬ ‫هیالدی‬BBC One
•General-Purpose
•Open Source
•High-Level:Machine < Assembly < C < C++ < Java < Pytho
•Dynamic:ِ‫حافظ‬ ‫خَدکار‬ ‫هدیریت‬
•Multi-Paradigm:‫دستَری‬(Imperative)‫ای‬ِ‫رٍی‬ ‫یا‬(Procedural)
‫تابعی‬(Functional)‫گرایی‬‫شی‬ ٍ(Object-Oriented)
MoinMoin
،‫ٍرٍدی‬‫خرٍجی‬‫ٍارد‬ ٍ‫کردى‬(I/O/I)
‫ّا‬ ‫هتغیر‬
‫عولگر‬‫ّا‬
‫شرط‬if
ِ‫حلق‬for
Input
Output
Import
print function
>>> print('This is our CFD class.')
This is our CFD class.
>>> a = 5
>>> print(a)
5
>>> x = 5; y = 10
>>> print('The value of x is {} and y is {}'.format(x,y))
The value of x is 5 and y is 10
>>> print('I prefer {0} to {1}'.format('MUFC', 'LFC'))
I prefer MUFC to LFC
>>> print('Hello {name},
{greeting}'.format(greeting='Goodmorning',name='John'))
Hello John, Goodmorning
Input
input function input('prompt')
>>> num = input('Enter a number: ')
Enter a number: 10
>>> num
10
Module program grows bigger
containing Python definitions
import keyword to use
>>> import math
>>> math.pi
3.141592653589793
>>> from math import pi
>>> pi
3.141592653589793
>>> import sys
>>> sys.path
['', 'C:Python27Libidlelib',
'C:Windowssystem32python27.zip',
'C:Python27DLLs', 'C:Python27lib',
'C:Python27libplat-win', 'C:Python27liblib-tk',
'C:Python27', 'C:Python27libsite-packages']
Variable
Datatype
Conversion
 A location in memory used to store some data
 We don't have to declare the type of the variable
 We use the (=) to assign values to a variable
>>>a = 5 integer
>>>b = 3.2 floating point
>>>c = "Hello“ string
>>>a, b, c = 5, 3.2, "Hello "
>>>a=5; b=10’; c= " Hello "
x = y = z = "same"
 Every value has a datatype
 Important Dataypes:
Numbers
List
Tuple
Strings
Use the type() function to know the class
the isinstance() function to check if an object belongs to
a particular class
 Integers int
 floating point float 17 decimal
 Complex complex
>>> a = 5
>>> type(a)
<class 'int'>
>>> type(2.0)
<class 'float'>
>>> isinstance(1+2j,complex)
True
1 is int 1.0 is float
 An ordered sequence of items
 Flexible
 The items in a list do not need to be of the same type
>>> a = [1, 2.2, 'python']
>>> type(a)
<class 'list'>
>>> a = [5,10,15,20,25,30,35,40]
>>> a[2]
15
>>> a[0:3]
[5, 10, 15]
>>> a[5:]
[30, 35, 40]
>>> a[2]=21
>>> a
[5, 10, ,20,25,30,35,40]
 An ordered sequence of items
 Immutable so faster than list
 Write-protect data
 Defined within parentheses ()
>>> t = (5,'program', 1+3j)
>>> type(t)
<class 'tuple'>
>>> t[1]
'program'
>>> t[0:3]
(5, 'program', (1+3j))
>>> t[0] = 10
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in
<module>
TypeError: 'tuple' object does not support
item assignment
 sequence of Unicode characters
 ' … ' or " … “
>>> s = "This is our CFD calss"
>>> type(s)
<class 'str'>
>>> s = 'Hello world!'
>>> s[4]
'o'
>>> s[6:11]
'world'
>>> s[5] ='d'
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
TypeError: 'str' object does not support item assignment
>>> float(5)
5.0
>>> int(10.6)
10
>>> int(-10.6)
-10
>>> float('2.5')
2.5
>>> str(25)
'25'
>>> int('1p')
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1p'
>>> tuple([5,6,7])
(5, 6, 7)
>>> list('hello')
['h', 'e', 'l', 'l', 'o']
Arithmetic
Comparison (Relational)
Logical (Boolean)
Bitwise
Assignment
Special
Operator Meaning Example
+ Add two operands or unary plus
x + y
+2
- Subtract right operand from the left or unary minus
x - y
-2
* Multiply two operands x * y
/
Divide left operand by the right one (always results into
float)
x / y
%
Modulus - remainder of the division of left operand by
the right
x % y (remainder of x/y)
//
Floor division - division that results into whole number
adjusted to the left in the number line
x // y
** Exponent - left operand raised to the power of right x**y (x to the power y)
x = 15; y = 4
print('x + y = ',x+y)
print('x - y = ',x-y)
print('x * y = ',x*y)
print('x / y = ',x/y)
print('x // y = ',x//y)
print('x ** y = ',x**y)
Output
x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625
Operator Meaning Example
> Greater that - True if left operand is greater than the right x > y
< Less that - True if left operand is less than the right x < y
== Equal to - True if both operands are equal x == y
!= Not equal to - True if operands are not equal x != y
>=
Greater than or equal to - True if left operand is greater than or
equal to the right
x >= y
<=
Less than or equal to - True if left operand is less than or equal to
the right
x <= y
x = 10; y = 12
print('x > y is',x>y)
print('x < y is',x<y)
print('x == y is',x==y)
print('x != y is',x!=y)
print('x >= y is',x>=y)
print('x <= y is',x<=y)
Output
x > y is False
x < y is True
x == y is False
x != y is True
x >= y is False
x <= y is True
Operator Meaning Example
and True if both the operands are true x and y
or True if either of the operands is true x or y
not True if operand is false (complements the operand) not x
x = True; y = False
print('x and y is',x and y)
print('x or y is',x or y)
print('not x is',not x)
Output
x and y is False
x or y is True
not x is False
Operator Meaning Example
& Bitwise AND x& y = 0 (0000 0000)
| Bitwise OR x | y = 14 (0000 1110)
~ Bitwise NOT ~x = -11 (1111 0101)
^ Bitwise XOR x ^ y = 14 (0000 1110)
>> Bitwise right shift x>> 2 = 2 (0000 0010)
<< Bitwise left shift x<< 2 = 42 (0010 1000)
x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)
Operator Example Equivatent to
= x = 5 x = 5
+= x += 5 x = x + 5
-= x -= 5 x = x - 5
*= x *= 5 x = x * 5
/= x /= 5 x = x / 5
%= x %= 5 x = x % 5
//= x //= 5 x = x // 5
**= x **= 5 x = x ** 5
&= x &= 5 x = x & 5
|= x |= 5 x = x | 5
^= x ^= 5 x = x ^ 5
>>= x >>= 5 x = x >> 5
<<= x <<= 5 x = x << 5
Operator Meaning Example
is
True if the operands are identical (refer to the
same object)
x is True
is not
True if the operands are not identical (do not
refer to the same object)
x is not True
in True if value/variable is found in the sequence 5 in x
not in
True if value/variable is not found in the
sequence
5 not in x
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]
print(x1 is not y1)
print(x2 is y2)
print(x3 is y3)
Output
False
True
False
If
Else
Elif
Nesting
 if test expression:
statement(s) Indentation
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
print("This is always printed")
Output 1
Enter a number: 3
Positive numberThis is always printed
Output 2
Enter a number: -1
This is always printed
if test expression:
Body of if
else:
Body of else
num = float(input("Enter a number: "))
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
Output 1
Enter a number: 2
Positive or Zero
Output 2
Enter a number: -3
Negative number
if test expression:
Body of if
else:
Body of else
elif:
Body of elif
num = float(input("Enter a number:
"))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
Output 1
Enter a number: 2
Positive number
Output 2
Enter a number: 0
Zero
Output 3
Enter a number: -2
Negative number
num = float(input("Enter a
number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive
number")
else:
print("Negative number")
Output 1
Enter a number: 5
Positive number
Output 2
Enter a number: -1
Negative number
Output 3
Enter a number: 0
Zero
For
Range
For loop with else
Iterate over a sequence (list, tuple, string)
 Traversal
for val in sequence:
Body of for
val is the variable that takes the value of
the item inside the sequence on each
iteration
# List of numbers
numbers = [6,5,3,8,4,2,5,4,11]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
# print the sum
print("The sum is{}“.format(sum))
Output
The sum is 48
 generate a sequence of
numbers
 range(start,stop,step)
 Just save
start, stop and step
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> range(2,5)
[2, 3, 4]
>>> range(2,15,2)
[2, 4, 6, 8, 10, 12, 14]
player = ['pop','rock','jazz']
# iterate over the list using index
for i in range(len(player)):
print("I like",genre[i])
Output
I like pop
I like rock
I like jazz
 The else part is executed if
the items in the sequence
used in for loop exhausts
 break statement use to
stop a for loop
# a list of digit
LOD = [0,1,2,3,4,5,6]
#take input from user
input_digit = int(input("Enter a
digit: "))
# search the input digit in our list
for i in LOD:
If input_digit == i:
print("Digit is in the list")
break
else:
print("Digit not found in list")
Output 1
Enter a digit: 3
Digit is in the list
Output 2
Enter a digit: 9
Digit not found in list
‫ّریس‬ ُ‫زاد‬ ‫کاظن‬ ‫پَریا‬

More Related Content

What's hot

Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...ssuserd6b1fd
 
Row-based Effect Systems for Algebraic Effect Handlers
Row-based Effect Systems for Algebraic Effect HandlersRow-based Effect Systems for Algebraic Effect Handlers
Row-based Effect Systems for Algebraic Effect HandlersTaro Sekiyama
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...ssuserd6b1fd
 
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88Mahmoud Samir Fayed
 
F# Presentation
F# PresentationF# Presentation
F# Presentationmrkurt
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONvikram mahendra
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
2 2. operators
2 2. operators2 2. operators
2 2. operators웅식 전
 
The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181Mahmoud Samir Fayed
 
Python real time tutorial
Python real time tutorialPython real time tutorial
Python real time tutorialRajeev Kumar
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180Mahmoud Samir Fayed
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]vikram mahendra
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital waveRahulSharma4566
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84Mahmoud Samir Fayed
 

What's hot (20)

Fekra c++ Course #2
Fekra c++ Course #2Fekra c++ Course #2
Fekra c++ Course #2
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 
Row-based Effect Systems for Algebraic Effect Handlers
Row-based Effect Systems for Algebraic Effect HandlersRow-based Effect Systems for Algebraic Effect Handlers
Row-based Effect Systems for Algebraic Effect Handlers
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
 
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.3 book - Part 11 of 88
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
F# Presentation
F# PresentationF# Presentation
F# Presentation
 
USER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHONUSER DEFINE FUNCTIONS IN PYTHON
USER DEFINE FUNCTIONS IN PYTHON
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Minimization model by simplex method
Minimization model by simplex methodMinimization model by simplex method
Minimization model by simplex method
 
2 2. operators
2 2. operators2 2. operators
2 2. operators
 
The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.5.2 book - Part 18 of 181
 
Python real time tutorial
Python real time tutorialPython real time tutorial
Python real time tutorial
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
Operators
OperatorsOperators
Operators
 
4. operators in c programming by digital wave
4. operators in  c programming by digital wave4. operators in  c programming by digital wave
4. operators in c programming by digital wave
 
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 9 of 84
 
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 12 of 84
 

Viewers also liked

Rescuing Leftovers - 221 Mentos
Rescuing Leftovers - 221 Mentos Rescuing Leftovers - 221 Mentos
Rescuing Leftovers - 221 Mentos Boru Chen
 
Mueller Presentation
Mueller PresentationMueller Presentation
Mueller PresentationWill Mueller
 
Austrix Digital Signage Directory
Austrix Digital Signage DirectoryAustrix Digital Signage Directory
Austrix Digital Signage DirectorySHAKEEL AHAMMED
 
San Luis Obispo County Investment Pool
San Luis Obispo County Investment PoolSan Luis Obispo County Investment Pool
San Luis Obispo County Investment PoolDaniel Rodriguez
 
Is Your Corporate Culture Aligned For Success?
Is Your Corporate Culture Aligned For Success?Is Your Corporate Culture Aligned For Success?
Is Your Corporate Culture Aligned For Success?Dorriah Rogers
 
Reading models dev. read
Reading models dev. readReading models dev. read
Reading models dev. readJane Jerrah
 

Viewers also liked (9)

Rescuing Leftovers - 221 Mentos
Rescuing Leftovers - 221 Mentos Rescuing Leftovers - 221 Mentos
Rescuing Leftovers - 221 Mentos
 
Mueller Presentation
Mueller PresentationMueller Presentation
Mueller Presentation
 
NewsInfo
NewsInfoNewsInfo
NewsInfo
 
Austrix Digital Signage Directory
Austrix Digital Signage DirectoryAustrix Digital Signage Directory
Austrix Digital Signage Directory
 
San Luis Obispo County Investment Pool
San Luis Obispo County Investment PoolSan Luis Obispo County Investment Pool
San Luis Obispo County Investment Pool
 
dia m t
dia m tdia m t
dia m t
 
Is Your Corporate Culture Aligned For Success?
Is Your Corporate Culture Aligned For Success?Is Your Corporate Culture Aligned For Success?
Is Your Corporate Culture Aligned For Success?
 
A Warehouse Visit
A Warehouse VisitA Warehouse Visit
A Warehouse Visit
 
Reading models dev. read
Reading models dev. readReading models dev. read
Reading models dev. read
 

Similar to Python

Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionElsayed Hemayed
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdfMILANOP1
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptxMAHAMASADIK
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfJkPoppy
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
Pythonlearn-03-Conditional.pptx
Pythonlearn-03-Conditional.pptxPythonlearn-03-Conditional.pptx
Pythonlearn-03-Conditional.pptxVigneshChaturvedi1
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
Python 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptxPython 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptxTseChris
 
C language operator
C language operatorC language operator
C language operatorcprogram
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثةجامعة القدس المفتوحة
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxSALU18
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 

Similar to Python (20)

Csci101 lect04 advanced_selection
Csci101 lect04 advanced_selectionCsci101 lect04 advanced_selection
Csci101 lect04 advanced_selection
 
Data Handling
Data Handling Data Handling
Data Handling
 
Data Handling.pdf
Data Handling.pdfData Handling.pdf
Data Handling.pdf
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
 
C tutorial
C tutorialC tutorial
C tutorial
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
Swift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdfSwift 5.1 Language Guide Notes.pdf
Swift 5.1 Language Guide Notes.pdf
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
Pythonlearn-03-Conditional.pptx
Pythonlearn-03-Conditional.pptxPythonlearn-03-Conditional.pptx
Pythonlearn-03-Conditional.pptx
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Python.pptx
Python.pptxPython.pptx
Python.pptx
 
Python 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptxPython 04-ifelse-return-input-strings.pptx
Python 04-ifelse-return-input-strings.pptx
 
C language operator
C language operatorC language operator
C language operator
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
Operators
OperatorsOperators
Operators
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
 
Php & my sql
Php & my sqlPhp & my sql
Php & my sql
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 

Recently uploaded

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfRagavanV2
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 

Recently uploaded (20)

FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 

Python

  • 1. ‫استاد‬:ُ‫زاد‬ ‫اهام‬ ‫هحود‬ ‫درس‬:ِ‫هقده‬‫هحاسباتی‬ ‫سیاالت‬ ‫بر‬ ‫ای‬ ‫دٍم‬ ‫ًیوسال‬94-95 ‫ّریس‬ ُ‫زاد‬ ‫کاظن‬ ‫پَریا‬ 910284261
  • 2. •1982–1991‫رٍسَم‬ ‫في‬ ٍ‫گَید‬ •‫عٌَاى‬ ‫با‬ ‫اًگلستاى‬ ‫تَلید‬ ‫کودی‬ ‫سریال‬Monty Python’s Flying Circus ‫از‬1969‫تا‬1974ِ‫شبک‬ ‫از‬ ‫هیالدی‬BBC One •General-Purpose •Open Source •High-Level:Machine < Assembly < C < C++ < Java < Pytho •Dynamic:ِ‫حافظ‬ ‫خَدکار‬ ‫هدیریت‬ •Multi-Paradigm:‫دستَری‬(Imperative)‫ای‬ِ‫رٍی‬ ‫یا‬(Procedural) ‫تابعی‬(Functional)‫گرایی‬‫شی‬ ٍ(Object-Oriented)
  • 3.
  • 4.
  • 5.
  • 6.
  • 10. print function >>> print('This is our CFD class.') This is our CFD class. >>> a = 5 >>> print(a) 5 >>> x = 5; y = 10 >>> print('The value of x is {} and y is {}'.format(x,y)) The value of x is 5 and y is 10
  • 11. >>> print('I prefer {0} to {1}'.format('MUFC', 'LFC')) I prefer MUFC to LFC >>> print('Hello {name}, {greeting}'.format(greeting='Goodmorning',name='John')) Hello John, Goodmorning Input input function input('prompt') >>> num = input('Enter a number: ') Enter a number: 10 >>> num 10
  • 12. Module program grows bigger containing Python definitions import keyword to use >>> import math >>> math.pi 3.141592653589793 >>> from math import pi >>> pi 3.141592653589793
  • 13. >>> import sys >>> sys.path ['', 'C:Python27Libidlelib', 'C:Windowssystem32python27.zip', 'C:Python27DLLs', 'C:Python27lib', 'C:Python27libplat-win', 'C:Python27liblib-tk', 'C:Python27', 'C:Python27libsite-packages']
  • 14.
  • 16.  A location in memory used to store some data  We don't have to declare the type of the variable  We use the (=) to assign values to a variable >>>a = 5 integer >>>b = 3.2 floating point >>>c = "Hello“ string >>>a, b, c = 5, 3.2, "Hello " >>>a=5; b=10’; c= " Hello " x = y = z = "same"
  • 17.  Every value has a datatype  Important Dataypes: Numbers List Tuple Strings Use the type() function to know the class the isinstance() function to check if an object belongs to a particular class
  • 18.  Integers int  floating point float 17 decimal  Complex complex >>> a = 5 >>> type(a) <class 'int'> >>> type(2.0) <class 'float'> >>> isinstance(1+2j,complex) True 1 is int 1.0 is float
  • 19.  An ordered sequence of items  Flexible  The items in a list do not need to be of the same type >>> a = [1, 2.2, 'python'] >>> type(a) <class 'list'> >>> a = [5,10,15,20,25,30,35,40] >>> a[2] 15 >>> a[0:3] [5, 10, 15] >>> a[5:] [30, 35, 40] >>> a[2]=21 >>> a [5, 10, ,20,25,30,35,40]
  • 20.  An ordered sequence of items  Immutable so faster than list  Write-protect data  Defined within parentheses () >>> t = (5,'program', 1+3j) >>> type(t) <class 'tuple'> >>> t[1] 'program' >>> t[0:3] (5, 'program', (1+3j)) >>> t[0] = 10 Traceback (most recent call last): File "<string>", line 301, in runcode File "<interactive input>", line 1, in <module> TypeError: 'tuple' object does not support item assignment
  • 21.  sequence of Unicode characters  ' … ' or " … “ >>> s = "This is our CFD calss" >>> type(s) <class 'str'> >>> s = 'Hello world!' >>> s[4] 'o' >>> s[6:11] 'world' >>> s[5] ='d' Traceback (most recent call last): File "<string>", line 301, in runcode File "<interactive input>", line 1, in <module> TypeError: 'str' object does not support item assignment
  • 22. >>> float(5) 5.0 >>> int(10.6) 10 >>> int(-10.6) -10 >>> float('2.5') 2.5 >>> str(25) '25' >>> int('1p') Traceback (most recent call last): File "<string>", line 301, in runcode File "<interactive input>", line 1, in <module> ValueError: invalid literal for int() with base 10: '1p' >>> tuple([5,6,7]) (5, 6, 7) >>> list('hello') ['h', 'e', 'l', 'l', 'o']
  • 24. Operator Meaning Example + Add two operands or unary plus x + y +2 - Subtract right operand from the left or unary minus x - y -2 * Multiply two operands x * y / Divide left operand by the right one (always results into float) x / y % Modulus - remainder of the division of left operand by the right x % y (remainder of x/y) // Floor division - division that results into whole number adjusted to the left in the number line x // y ** Exponent - left operand raised to the power of right x**y (x to the power y)
  • 25. x = 15; y = 4 print('x + y = ',x+y) print('x - y = ',x-y) print('x * y = ',x*y) print('x / y = ',x/y) print('x // y = ',x//y) print('x ** y = ',x**y) Output x + y = 19 x - y = 11 x * y = 60 x / y = 3.75 x // y = 3 x ** y = 50625
  • 26. Operator Meaning Example > Greater that - True if left operand is greater than the right x > y < Less that - True if left operand is less than the right x < y == Equal to - True if both operands are equal x == y != Not equal to - True if operands are not equal x != y >= Greater than or equal to - True if left operand is greater than or equal to the right x >= y <= Less than or equal to - True if left operand is less than or equal to the right x <= y
  • 27. x = 10; y = 12 print('x > y is',x>y) print('x < y is',x<y) print('x == y is',x==y) print('x != y is',x!=y) print('x >= y is',x>=y) print('x <= y is',x<=y) Output x > y is False x < y is True x == y is False x != y is True x >= y is False x <= y is True
  • 28. Operator Meaning Example and True if both the operands are true x and y or True if either of the operands is true x or y not True if operand is false (complements the operand) not x
  • 29. x = True; y = False print('x and y is',x and y) print('x or y is',x or y) print('not x is',not x) Output x and y is False x or y is True not x is False
  • 30. Operator Meaning Example & Bitwise AND x& y = 0 (0000 0000) | Bitwise OR x | y = 14 (0000 1110) ~ Bitwise NOT ~x = -11 (1111 0101) ^ Bitwise XOR x ^ y = 14 (0000 1110) >> Bitwise right shift x>> 2 = 2 (0000 0010) << Bitwise left shift x<< 2 = 42 (0010 1000) x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)
  • 31. Operator Example Equivatent to = x = 5 x = 5 += x += 5 x = x + 5 -= x -= 5 x = x - 5 *= x *= 5 x = x * 5 /= x /= 5 x = x / 5 %= x %= 5 x = x % 5 //= x //= 5 x = x // 5 **= x **= 5 x = x ** 5 &= x &= 5 x = x & 5 |= x |= 5 x = x | 5 ^= x ^= 5 x = x ^ 5 >>= x >>= 5 x = x >> 5 <<= x <<= 5 x = x << 5
  • 32. Operator Meaning Example is True if the operands are identical (refer to the same object) x is True is not True if the operands are not identical (do not refer to the same object) x is not True in True if value/variable is found in the sequence 5 in x not in True if value/variable is not found in the sequence 5 not in x
  • 33. x1 = 5 y1 = 5 x2 = 'Hello' y2 = 'Hello' x3 = [1,2,3] y3 = [1,2,3] print(x1 is not y1) print(x2 is y2) print(x3 is y3) Output False True False
  • 34.
  • 36.  if test expression: statement(s) Indentation num = float(input("Enter a number: ")) if num > 0: print("Positive number") print("This is always printed") Output 1 Enter a number: 3 Positive numberThis is always printed Output 2 Enter a number: -1 This is always printed
  • 37. if test expression: Body of if else: Body of else num = float(input("Enter a number: ")) if num >= 0: print("Positive or Zero") else: print("Negative number") Output 1 Enter a number: 2 Positive or Zero Output 2 Enter a number: -3 Negative number
  • 38. if test expression: Body of if else: Body of else elif: Body of elif num = float(input("Enter a number: ")) if num > 0: print("Positive number") elif num == 0: print("Zero") else: print("Negative number") Output 1 Enter a number: 2 Positive number Output 2 Enter a number: 0 Zero Output 3 Enter a number: -2 Negative number
  • 39. num = float(input("Enter a number: ")) if num >= 0: if num == 0: print("Zero") else: print("Positive number") else: print("Negative number") Output 1 Enter a number: 5 Positive number Output 2 Enter a number: -1 Negative number Output 3 Enter a number: 0 Zero
  • 40.
  • 42. Iterate over a sequence (list, tuple, string)  Traversal for val in sequence: Body of for val is the variable that takes the value of the item inside the sequence on each iteration
  • 43. # List of numbers numbers = [6,5,3,8,4,2,5,4,11] # variable to store the sum sum = 0 # iterate over the list for val in numbers: sum = sum+val # print the sum print("The sum is{}“.format(sum)) Output The sum is 48
  • 44.  generate a sequence of numbers  range(start,stop,step)  Just save start, stop and step >>> range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> range(2,5) [2, 3, 4] >>> range(2,15,2) [2, 4, 6, 8, 10, 12, 14] player = ['pop','rock','jazz'] # iterate over the list using index for i in range(len(player)): print("I like",genre[i]) Output I like pop I like rock I like jazz
  • 45.  The else part is executed if the items in the sequence used in for loop exhausts  break statement use to stop a for loop # a list of digit LOD = [0,1,2,3,4,5,6] #take input from user input_digit = int(input("Enter a digit: ")) # search the input digit in our list for i in LOD: If input_digit == i: print("Digit is in the list") break else: print("Digit not found in list") Output 1 Enter a digit: 3 Digit is in the list Output 2 Enter a digit: 9 Digit not found in list
  • 46.