SlideShare a Scribd company logo
1 of 27
Download to read offline
CS.QIAU - Winter 2020
PYTHONBasic Parts - Session 1
Omid AmirGhiasvand
Programming
Identifier
โ–ธ Is a name given to a variable, function, class or module.
โ–ธ Can only contain letter and number and underscore.
โ–ธ my_list_11
โ–ธ They can start just with letter or underscore.
โ–ธ Space are not allows in variable name.
โ–ธ use underscore instead
โ–ธ Python keywords can not be used as identi๏ฌers.
โ–ธ Python is case sensitive.
โ–ธ โ€œNameโ€ and โ€œnameโ€ are 2 different identi๏ฌers!
โ–ธ Always use meaningful name for identi๏ฌer.
Identifier
Identi๏ฌer Valid Not Valid
Good Bad
name
17name
%name
x
students_list
x-list
for
teacher id
Best Practice
Keyword
space
Keywords
โ–ธ Keywords are a list of reserved words that have prede๏ฌned meaning.
Python Keywords
def with in True
return for is False
class while and None
break if or global
continue elif not nonlocal
try else as from
except pass import
๏ฌnally assert raise
Statements and Expression
โ–ธ A Statement is an Instruction that the Python Interpreter can execute.
โ–ธ welcome_message=โ€œWelcome To Pythonโ€
โ–ธ A Python Program consist of a sequence of statements.
โ–ธ An statement can be one or several line of code.
โ–ธ Expression is an arrangement of values and operators which are
evaluated to make a new value.
โ–ธ Expressions are statements as well.
โ–ธ total_payment = monthly_rate * 12
assignment statement
Variable
โ–ธ Variable are used in programming language to hold value.
โ–ธ The variableโ€™s value is actually the Information associated with that variable
name.
โ–ธ variable = expression or single value
โ–ธ age = 0
โ–ธ age = 11 * 3
โ–ธ payment = h_rate * 100
36age Memory
Location
variable
name
Naming Convention
โ–ธ Compare these two statements:
โ–ธ S1
โ–ธ S2
1. c = a * b
1. weekly_pay = hours_worked * hourly_pay_rate
Best Practice
โ–ธ Arithmetic operators are used to execute arithmetic operations
Arithmetic Operators
Operator Operator Name Example
+ Additional 3 + 5
- Subtraction 3 - 5
* Multiplication 3 * 5
/ Division 7 / 3
% Modulus 7 % 3
** Exponent 2 ** 10
// Floor division 7 // 3
result is 2
โ–ธ Arithmetic Assignment operators are used for assigning the values
generated after evaluating the right operand to the left operand
Assignment Operators
Operator Operator Name Example
.= Assignment age = 21
+= Additional Assignment age +=2
-= Subtraction Assignment age -=2
*= Multiplication Assignment age *=age
/= Division Assignment result /=2
**= Exponential Assignment k **= 10
//= Floor Division Assignment result //=2
%= Reminder Assignment result %=2
Variable must be initialized before used
โ–ธ Arithmetic Assignment operators are used for assigning the values
generated after evaluating the right operand to the left operand
Comparison Operators
Operator Operator Name Example
.== Equal to age == 21
!= Not Equal to age != -1
> Greater Than age > 18
< Lesser Than age < 35
>= Greater Than or Equal to age >= 30
<= Lesser Than or Equal to age <= 29
โ–ธ The logical operators are used for comparing or negating the logical
values of their operands and to return results logical value
Logical Operators
Operator Operator Name Example
and Logical AND age > 18 and sex==male
or Logical OR age > 18 or sex==male
not Logical NOT not age > 12
Precedence
โ–ธ Operator precedence determines the way in which operators are
parsed with respect to each other.
Operator Operator Name
() Parantheses
** Exponent
+x,-x Unary Plus, Unary Minus
*,/,//,% Multiplication, Division, Floor division, Modulus
+,- Addition, Subtraction
!=,==,>=,<=,>,< Comparisons
in, is, not in, is not Identity, Membership operators
not Logical NOT
and Logical AND
or Logical OR
Operators with higher precedence become the operands of operators with lower precedence.
Data Types
โ–ธ Strings
โ–ธ className=โ€œPython Programmingโ€
โ–ธ Number
โ–ธ age = 22
โ–ธ avg = 12.45
โ–ธ Boolean
โ–ธ male = False
โ–ธ None - The absence of value
โ–ธ validEmail = None
All numbers are True and just 0 is False
built-in
function
IN PYTHON THERE
IS NO ; OR { }
Not like Java or C++
Indentation & Blocks
โ–ธ In Python, Programs get structured through indentation
In Python indentation is a requirement and not
a matter of style or convention
Block 1
Block 1 - Continue
Block 2
Block 2 - Continue
Block 3
Comments
โ–ธ Allow you to write comments and notes and also disable some part of
your code.
โ–ธ Comment Types
โ–ธ Single-line: Hash mark indicate single line comments. Anything follow # is
ignored by the python compiler/interpreter
โ–ธ Multi-line comment using โ€˜โ€™โ€™ โ€ฆ โ€˜โ€™'
1. #This is a single line comment
2. โ€˜โ€™โ€™ Start of multi-line commenting
3. โ€ฆ
4. โ€ฆ
5. End of multi-line commentingโ€™โ€™โ€™
3 single
quotation
Input/Output
โ–ธ In Python, input() function is used to gather data from the user.
โ–ธ The print() function allows a program to display text onto the console.
1. name = input(โ€œEnter your name:โ€)
1. print(fโ€your name is {name}โ€)
f-string
variable or
expression
Formatted String
โ–ธ Formatted String or f-strings were introduced in Python 3.6
โ–ธ f-string is a string literal that is pre๏ฌxed with โ€œfโ€.
โ–ธ The string may contain replacement ๏ฌelds.
โ–ธ which are expressions enclosed within curly braces {}
Using f-string
formatting
Type Conversions
โ–ธ You can explicitly cast or convert a variable from one type to another.
โ–ธ int()
โ–ธ str()
โ–ธ ๏ฌ‚oat()
โ–ธ chr()
age = int(value)
cast to
int
Casting
input function
return string
real_age is int
after casting
input and
casting in one line
age is int
you can not
subtract from str
Exception
age is str
DISCOVERFOR YOURSELF
Change things and see what will happens. Noting going to BREAK :)
โ€œThe Unexamined Life Is Not Worth Livingโ€

More Related Content

What's hot

5 structured programming
5 structured programming 5 structured programming
5 structured programming hccit
ย 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithmshccit
ย 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy
ย 
C++ ppt
C++ pptC++ ppt
C++ pptparpan34
ย 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Nuzhat Memon
ย 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ programmatiur rahman
ย 
Unit 3
Unit 3Unit 3
Unit 3rohassanie
ย 
C introduction
C introductionC introduction
C introductionKamran
ย 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answersvithyanila
ย 
Python - Functions - Azure Jupyter Notebooks
Python - Functions - Azure Jupyter NotebooksPython - Functions - Azure Jupyter Notebooks
Python - Functions - Azure Jupyter NotebooksAdri Jovin
ย 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Salahaddin University-Erbil
ย 
Lect '1'
Lect '1'Lect '1'
Lect '1'reena0098
ย 
Why C is Called Structured Programming Language
Why C is Called Structured Programming LanguageWhy C is Called Structured Programming Language
Why C is Called Structured Programming LanguageSinbad Konick
ย 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN BASHA
ย 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesArghodeepPaul
ย 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c languagekamalbeydoun
ย 

What's hot (20)

5 structured programming
5 structured programming 5 structured programming
5 structured programming
ย 
4 coding from algorithms
4 coding from algorithms4 coding from algorithms
4 coding from algorithms
ย 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testing
ย 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
ย 
C++ ppt
C++ pptC++ ppt
C++ ppt
ย 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
ย 
Basic structure of C++ program
Basic structure of C++ programBasic structure of C++ program
Basic structure of C++ program
ย 
Algorithms
AlgorithmsAlgorithms
Algorithms
ย 
Unit 3
Unit 3Unit 3
Unit 3
ย 
C introduction
C introductionC introduction
C introduction
ย 
C language function
C language functionC language function
C language function
ย 
265 ge8151 problem solving and python programming - 2 marks with answers
265   ge8151 problem solving and python programming - 2 marks with answers265   ge8151 problem solving and python programming - 2 marks with answers
265 ge8151 problem solving and python programming - 2 marks with answers
ย 
Python - Functions - Azure Jupyter Notebooks
Python - Functions - Azure Jupyter NotebooksPython - Functions - Azure Jupyter Notebooks
Python - Functions - Azure Jupyter Notebooks
ย 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
ย 
Lect '1'
Lect '1'Lect '1'
Lect '1'
ย 
Preprocessor
PreprocessorPreprocessor
Preprocessor
ย 
Why C is Called Structured Programming Language
Why C is Called Structured Programming LanguageWhy C is Called Structured Programming Language
Why C is Called Structured Programming Language
ย 
SULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notesSULTHAN's - C Programming Language notes
SULTHAN's - C Programming Language notes
ย 
Algorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notesAlgorithm pseudocode flowchart program notes
Algorithm pseudocode flowchart program notes
ย 
Algorithm and c language
Algorithm and c languageAlgorithm and c language
Algorithm and c language
ย 

Similar to Python Programming - Basic Parts

1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdfMaheshGour5
ย 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python Mohammed Sikander
ย 
basics of python programming5.pdf
basics of python programming5.pdfbasics of python programming5.pdf
basics of python programming5.pdfPushkaran3
ย 
Python Control structures
Python Control structuresPython Control structures
Python Control structuresSiddique Ibrahim
ย 
Python Lecture 2
Python Lecture 2Python Lecture 2
Python Lecture 2Inzamam Baig
ย 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in PythonSumit Satam
ย 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdfRohitSindhu10
ย 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshopMukul Kirti Verma
ย 
introduction to python in english presentation file
introduction to python in english presentation fileintroduction to python in english presentation file
introduction to python in english presentation fileRujanTimsina1
ย 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language CourseVivek chan
ย 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa Thapa
ย 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsMuhammadTalha436
ย 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionsaber tabatabaee
ย 
Python programing
Python programingPython programing
Python programinghamzagame
ย 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)ExcellenceAcadmy
ย 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)ExcellenceAcadmy
ย 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfEjazAlam23
ย 

Similar to Python Programming - Basic Parts (20)

1_Python Basics.pdf
1_Python Basics.pdf1_Python Basics.pdf
1_Python Basics.pdf
ย 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
ย 
basics of python programming5.pdf
basics of python programming5.pdfbasics of python programming5.pdf
basics of python programming5.pdf
ย 
Python Control structures
Python Control structuresPython Control structures
Python Control structures
ย 
Python Lecture 2
Python Lecture 2Python Lecture 2
Python Lecture 2
ย 
8- java language basics part2
8- java language basics part28- java language basics part2
8- java language basics part2
ย 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
ย 
pythonQuick.pdf
pythonQuick.pdfpythonQuick.pdf
pythonQuick.pdf
ย 
python notes.pdf
python notes.pdfpython notes.pdf
python notes.pdf
ย 
python 34๐Ÿ’ญ.pdf
python 34๐Ÿ’ญ.pdfpython 34๐Ÿ’ญ.pdf
python 34๐Ÿ’ญ.pdf
ย 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
ย 
introduction to python in english presentation file
introduction to python in english presentation fileintroduction to python in english presentation file
introduction to python in english presentation file
ย 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
ย 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptxBikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa_Thapa_Python_Programming_(Basics).pptx
ย 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
ย 
clean code book summary - uncle bob - English version
clean code book summary - uncle bob - English versionclean code book summary - uncle bob - English version
clean code book summary - uncle bob - English version
ย 
Python programing
Python programingPython programing
Python programing
ย 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
ย 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
ย 
TOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdfTOPIC-2-Expression Variable Assignment Statement.pdf
TOPIC-2-Expression Variable Assignment Statement.pdf
ย 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto Gonzรกlez Trastoy
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธDelhi Call girls
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...OnePlan Solutions
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธanilsa9823
ย 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Steffen Staab
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
ย 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธcall girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
call girls in Vaishali (Ghaziabad) ๐Ÿ” >เผ’8448380779 ๐Ÿ” genuine Escort Service ๐Ÿ”โœ”๏ธโœ”๏ธ
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 

Python Programming - Basic Parts

  • 1. CS.QIAU - Winter 2020 PYTHONBasic Parts - Session 1 Omid AmirGhiasvand Programming
  • 2. Identifier โ–ธ Is a name given to a variable, function, class or module. โ–ธ Can only contain letter and number and underscore. โ–ธ my_list_11 โ–ธ They can start just with letter or underscore. โ–ธ Space are not allows in variable name. โ–ธ use underscore instead โ–ธ Python keywords can not be used as identi๏ฌers. โ–ธ Python is case sensitive. โ–ธ โ€œNameโ€ and โ€œnameโ€ are 2 different identi๏ฌers!
  • 3. โ–ธ Always use meaningful name for identi๏ฌer. Identifier Identi๏ฌer Valid Not Valid Good Bad name 17name %name x students_list x-list for teacher id Best Practice Keyword space
  • 4. Keywords โ–ธ Keywords are a list of reserved words that have prede๏ฌned meaning. Python Keywords def with in True return for is False class while and None break if or global continue elif not nonlocal try else as from except pass import ๏ฌnally assert raise
  • 5. Statements and Expression โ–ธ A Statement is an Instruction that the Python Interpreter can execute. โ–ธ welcome_message=โ€œWelcome To Pythonโ€ โ–ธ A Python Program consist of a sequence of statements. โ–ธ An statement can be one or several line of code. โ–ธ Expression is an arrangement of values and operators which are evaluated to make a new value. โ–ธ Expressions are statements as well. โ–ธ total_payment = monthly_rate * 12 assignment statement
  • 6. Variable โ–ธ Variable are used in programming language to hold value. โ–ธ The variableโ€™s value is actually the Information associated with that variable name. โ–ธ variable = expression or single value โ–ธ age = 0 โ–ธ age = 11 * 3 โ–ธ payment = h_rate * 100 36age Memory Location variable name
  • 7. Naming Convention โ–ธ Compare these two statements: โ–ธ S1 โ–ธ S2 1. c = a * b 1. weekly_pay = hours_worked * hourly_pay_rate Best Practice
  • 8. โ–ธ Arithmetic operators are used to execute arithmetic operations Arithmetic Operators Operator Operator Name Example + Additional 3 + 5 - Subtraction 3 - 5 * Multiplication 3 * 5 / Division 7 / 3 % Modulus 7 % 3 ** Exponent 2 ** 10 // Floor division 7 // 3 result is 2
  • 9. โ–ธ Arithmetic Assignment operators are used for assigning the values generated after evaluating the right operand to the left operand Assignment Operators Operator Operator Name Example .= Assignment age = 21 += Additional Assignment age +=2 -= Subtraction Assignment age -=2 *= Multiplication Assignment age *=age /= Division Assignment result /=2 **= Exponential Assignment k **= 10 //= Floor Division Assignment result //=2 %= Reminder Assignment result %=2 Variable must be initialized before used
  • 10. โ–ธ Arithmetic Assignment operators are used for assigning the values generated after evaluating the right operand to the left operand Comparison Operators Operator Operator Name Example .== Equal to age == 21 != Not Equal to age != -1 > Greater Than age > 18 < Lesser Than age < 35 >= Greater Than or Equal to age >= 30 <= Lesser Than or Equal to age <= 29
  • 11. โ–ธ The logical operators are used for comparing or negating the logical values of their operands and to return results logical value Logical Operators Operator Operator Name Example and Logical AND age > 18 and sex==male or Logical OR age > 18 or sex==male not Logical NOT not age > 12
  • 12. Precedence โ–ธ Operator precedence determines the way in which operators are parsed with respect to each other. Operator Operator Name () Parantheses ** Exponent +x,-x Unary Plus, Unary Minus *,/,//,% Multiplication, Division, Floor division, Modulus +,- Addition, Subtraction !=,==,>=,<=,>,< Comparisons in, is, not in, is not Identity, Membership operators not Logical NOT and Logical AND or Logical OR Operators with higher precedence become the operands of operators with lower precedence.
  • 13. Data Types โ–ธ Strings โ–ธ className=โ€œPython Programmingโ€ โ–ธ Number โ–ธ age = 22 โ–ธ avg = 12.45 โ–ธ Boolean โ–ธ male = False โ–ธ None - The absence of value โ–ธ validEmail = None All numbers are True and just 0 is False
  • 15.
  • 16. IN PYTHON THERE IS NO ; OR { } Not like Java or C++
  • 17. Indentation & Blocks โ–ธ In Python, Programs get structured through indentation In Python indentation is a requirement and not a matter of style or convention Block 1 Block 1 - Continue Block 2 Block 2 - Continue Block 3
  • 18. Comments โ–ธ Allow you to write comments and notes and also disable some part of your code. โ–ธ Comment Types โ–ธ Single-line: Hash mark indicate single line comments. Anything follow # is ignored by the python compiler/interpreter โ–ธ Multi-line comment using โ€˜โ€™โ€™ โ€ฆ โ€˜โ€™' 1. #This is a single line comment 2. โ€˜โ€™โ€™ Start of multi-line commenting 3. โ€ฆ 4. โ€ฆ 5. End of multi-line commentingโ€™โ€™โ€™ 3 single quotation
  • 19. Input/Output โ–ธ In Python, input() function is used to gather data from the user. โ–ธ The print() function allows a program to display text onto the console. 1. name = input(โ€œEnter your name:โ€) 1. print(fโ€your name is {name}โ€) f-string variable or expression
  • 20. Formatted String โ–ธ Formatted String or f-strings were introduced in Python 3.6 โ–ธ f-string is a string literal that is pre๏ฌxed with โ€œfโ€. โ–ธ The string may contain replacement ๏ฌelds. โ–ธ which are expressions enclosed within curly braces {}
  • 22. Type Conversions โ–ธ You can explicitly cast or convert a variable from one type to another. โ–ธ int() โ–ธ str() โ–ธ ๏ฌ‚oat() โ–ธ chr() age = int(value) cast to int
  • 24. input and casting in one line age is int
  • 25. you can not subtract from str Exception age is str
  • 26. DISCOVERFOR YOURSELF Change things and see what will happens. Noting going to BREAK :)
  • 27. โ€œThe Unexamined Life Is Not Worth Livingโ€