SlideShare a Scribd company logo
1 of 63
UNIT 2
VARIABLES AND DATA
TYPES IN PYTHON
Prof. Rushikesh V. Kolhe
Phd Pursuing, M.Tech Civil CM
Assistant Professor
Department of Civil Engineering
Sanjivani College of Engineering, Kopargaon
CONTENT
• What are variables ?
• String data type
• Numerical data type
• Examples
VARIABLES IN MATHS
• A symbol used to represent a numerical value
which can change
• 2x = y + 1 ( Algebra )
• x = 1, y = 1
• x = 2, y = 3
• Ten years from now, Rohit will be three times older
than he is today. What is his current age?
WHAT ARE VARIABLES
• Variables are used to store data
• These data are stored in main memory when you
run the program
• Programming = data + logic
• Different data types in python
• Numbers
• Strings
• Lists
• Tuple
• Dictionary
A SIMPLE EXAMPLE
• What is print() here ?
• What does it do ?
WHAT ARE FUNCTIONS IN MATHS
?
• Takes inputs and gives an output depending on the
input
• f(x) = x^2
• f(1) = 1
• f(2) = 4
• Programming functions also do the same.
• Takes input and returns output ( not always )
• Many built-in functions are present in python
• print() is one example – prints the input on screen
• More about functions in a separate video
WHY SHOULD I USE VARIABLES ?
• Using variables makes programs simpler
• Reduces repeated work
Naming Variables
• Can you give any name to the variables ?
• What are errors ?
WHAT ARE ERRORS IN PYTHON ?
• My name is Shivam vs Is name Shivam my ?
• My nam is Shivam vs My name is Shivam ?
• My name are Shivam vs My name is Shivam ?
• Every language has a syntax or a set of rules to
follow while writing it
• Python also has a syntax
• If you do not follow it, you will get errors.
• More about ”errors in python” in a separate video
RULES FOR NAMING
VARIABLES
RULE 1 - Variable names can contain only letters,
numbers, and underscores. They can start with a
letter or an underscore, but not with a number.
SUPPOSE YOU WANT TO WRITE TWO DIFFERENT MESSAGES ?
RULE 2 - Spaces are not allowed in variable names,
but underscores can be used to separate words in
variable names.
RULE 3 - Avoid using Python keywords and function
names as variable names; that is, do not use words
that Python has reserved for a particular
programmatic purpose, such as the word print.
WHAT ARE KEYWORDS IN PYTHON?
• These are reserved words in python which are used
to define the syntax of python language.
• In English, “is”, “the”, “you” etc. are reserved words
which defines the grammar.
• Keywords have different meaning for Python
language.
• Do not use them in your variables or function
names.
LIST OF KEYWORDS IN PYTHON
BUILT-IN FUNCTIONS IN PYTHON
SOME OTHER IMPORTANT POINTS TO
NOTE
• Variable names should be short but descriptive.
• name is better than writing n
• message is better than writing m or my_name_message
• Be careful when using the lowercase letter l and the
uppercase letter O because they could be confused
with the numbers 1 and 0.
It can take some practice to learn how to create good
variable names, especially as your programs become
more interesting and complicated. As you write more
programs and start to read through other people’s
code, you’ll get better at coming up with meaningful
names.
AVOIDING NAME ERRORS WHEN
USING VARIABLES
FINDING THE DATA TYPE OF A
VARIABLE
• Use type() built-in function
STRINGS DATA TYPE
WHAT ARE STRINGS ?
• A string is a series of characters
• Characters – alphabets, digits, special characters,
white spaces
• Anything inside quotes is considered a string in
Python
• You can use single or double quotes around your
strings
SINGLE QUOTE VS DOUBLE
QUOTE ?
• You can use any of these
• Be consistent
• Exceptions – print these text on screen:
• The language 'Python' is named after Monty Python, not
the snake.
• I told my friend, "Python is my favorite language!"
ASSIGNMENT: Try to find out if it is possible to print first message by using single quotes and second by using double quotes
and how ?
BUILT-IN FUNCTIONS
ASSOCIATED WITH
STRINGS
UPPER/LOWER FUNCTION
• print() vs message.lower()
• These built-in functions are specific to strings.
• print() is specific to multiple data types
• The dot(.) operator acts on the variable and
converts it into upper/lower cases
• The original data doesn’t change
TITLE FUNCTION
• Converts the first character of each word into
upper case
LEN FUNCTION
• Outputs the length of the string
• A single character is of length 1
• Characters can be alphabets or digits or
punctuation or white spaces
STRIP FUNCTIONS – strip(),
lstrip(), rstrip()
• Remove the extra whitespaces from a string
rstrip() – remove whitespace at
right end
lstrip() – remove whitespace from
left end
strip() – remove spaces from both
ends
USING VARIABLES
INSIDE A STRING
COMBINE THESE TWO TO
PRODUCE FULL NAME
Use f-strings
• Feature is available from python 3.6
• Start string with f – f stands for format
• Put braces around variable name
CONCAT MULTIPLE STRINGS
Adding Whitespace to Strings with
Tabs or Newlines
• In programming, whitespace refers to any
nonprinting character, such as spaces, tabs, and
end-of-line symbols.
• You can use whitespace to organize your output so
it’s easier for users to read.
Add a tab to your text
Add newline to your text
NUMBERS DATA TYPE
What are numbers ?
• Integers = 1, 2, 3
• Floats = 1.2, 2.55
• These data are used very frequently in a program.
INTEGERS
• You can add, subtract, multiply and divide python
integers
• Python uses two multiplication symbols to
represent exponents.
MULTIPLE OPERATORS IN ONE
EXPRESSION
• The spacing in these examples has no effect on how
Python evaluates the expressions
• Clarity
• More about precedence of operators in a future
video
FLOATS
• Python calls any number with a decimal point
a float.
• This term is used in most programming languages,
and it refers to the fact that a decimal point can
appear at any position in a number.
• Example: 1.2, 12.35
This happens in all languages and is of little concern. Python tries to find
a way to represent the result as precisely as possible, which is
sometimes difficult given how computers have to represent numbers
internally.
USE ROUND FUNCTION
INTEGERS AND FLOATS
DATA TYPE CONVERSION
MULTIPLE ASSIGNMENTS
• You can assign values to more than one variable
using just a single line.
• This can help shorten your programs and make
them easier to read.
• You’ll use this technique most often when
initializing a set of numbers.
CONSTANTS IN PYTHON
• A constant is like a variable whose value stays the
same throughout the life of a program.
• Python doesn’t have built-in constant types, but
Python programmers use all capital letters to
indicate a variable should be treated as a constant
and never be changed.

More Related Content

Similar to VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY

modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptxYusuf Ayuba
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxmuzammildev46gmailco
 
Advance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningAdvance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningsherinjoyson
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1Mohamed Abd Ela'al
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdfssuser9a6ca1
 
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfPy-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfshetoooelshitany74
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problemsRavikiran708913
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python ProgrammingKamal Acharya
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdfShivamKS4
 

Similar to VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY (20)

modul-python-part1.pptx
modul-python-part1.pptxmodul-python-part1.pptx
modul-python-part1.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
 
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptx
 
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
 
Advance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learningAdvance Python programming languages-Simple Easy learning
Advance Python programming languages-Simple Easy learning
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
17575602.ppt
17575602.ppt17575602.ppt
17575602.ppt
 
Raspberry using Python Session 1
Raspberry using Python Session 1Raspberry using Python Session 1
Raspberry using Python Session 1
 
Python Programming.pdf
Python Programming.pdfPython Programming.pdf
Python Programming.pdf
 
Python Training in Chandigarh
Python Training in ChandigarhPython Training in Chandigarh
Python Training in Chandigarh
 
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdfPy-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
Py-Slides- easuajsjsjejejjwlqpqpqpp1.pdf
 
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
 
Fundamentals of Python Programming
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
 
Python for katana
Python for katanaPython for katana
Python for katana
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdf
 
Python basics
Python basicsPython basics
Python basics
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python1
Python1Python1
Python1
 

More from Rushikesh Kolhe

Programming in Civil Engineering_UNIT 3_NOTES
Programming in Civil Engineering_UNIT 3_NOTESProgramming in Civil Engineering_UNIT 3_NOTES
Programming in Civil Engineering_UNIT 3_NOTESRushikesh Kolhe
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESRushikesh Kolhe
 
Programming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESProgramming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESRushikesh Kolhe
 
Why Python in required in Civil Engineering
Why Python in required in Civil EngineeringWhy Python in required in Civil Engineering
Why Python in required in Civil EngineeringRushikesh Kolhe
 
Introduction to Python Programming in Civil Engineering
Introduction to Python Programming in Civil EngineeringIntroduction to Python Programming in Civil Engineering
Introduction to Python Programming in Civil EngineeringRushikesh Kolhe
 
Smart city Developments in India
Smart city Developments in IndiaSmart city Developments in India
Smart city Developments in IndiaRushikesh Kolhe
 
Framework for Smart City
Framework for Smart CityFramework for Smart City
Framework for Smart CityRushikesh Kolhe
 
Human Resource Information System
Human Resource Information SystemHuman Resource Information System
Human Resource Information SystemRushikesh Kolhe
 
Human Resource Management: Training and Development (HRM)
Human Resource Management: Training and Development (HRM)Human Resource Management: Training and Development (HRM)
Human Resource Management: Training and Development (HRM)Rushikesh Kolhe
 
Work Breakdown Structure (WBS)
Work Breakdown Structure (WBS)Work Breakdown Structure (WBS)
Work Breakdown Structure (WBS)Rushikesh Kolhe
 
Materials Codification and Classification
Materials Codification and ClassificationMaterials Codification and Classification
Materials Codification and ClassificationRushikesh Kolhe
 
Economic Ordered Quantity (EOQ)
Economic Ordered Quantity (EOQ)Economic Ordered Quantity (EOQ)
Economic Ordered Quantity (EOQ)Rushikesh Kolhe
 
Materials Management in Civil Engineering
Materials Management in Civil EngineeringMaterials Management in Civil Engineering
Materials Management in Civil EngineeringRushikesh Kolhe
 
Ready Mix Concrete (RMC) Production Efficiency
Ready Mix Concrete (RMC) Production EfficiencyReady Mix Concrete (RMC) Production Efficiency
Ready Mix Concrete (RMC) Production EfficiencyRushikesh Kolhe
 
Ready Mix Concrete (RMC) quality controls
Ready Mix Concrete (RMC) quality controls Ready Mix Concrete (RMC) quality controls
Ready Mix Concrete (RMC) quality controls Rushikesh Kolhe
 

More from Rushikesh Kolhe (19)

Programming in Civil Engineering_UNIT 3_NOTES
Programming in Civil Engineering_UNIT 3_NOTESProgramming in Civil Engineering_UNIT 3_NOTES
Programming in Civil Engineering_UNIT 3_NOTES
 
Programming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTESProgramming in Civil Engineering_UNIT 2_NOTES
Programming in Civil Engineering_UNIT 2_NOTES
 
Programming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESProgramming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTES
 
Why Python in required in Civil Engineering
Why Python in required in Civil EngineeringWhy Python in required in Civil Engineering
Why Python in required in Civil Engineering
 
Introduction to Python Programming in Civil Engineering
Introduction to Python Programming in Civil EngineeringIntroduction to Python Programming in Civil Engineering
Introduction to Python Programming in Civil Engineering
 
Smart city Developments in India
Smart city Developments in IndiaSmart city Developments in India
Smart city Developments in India
 
Framework for Smart City
Framework for Smart CityFramework for Smart City
Framework for Smart City
 
E governance.pptx
E governance.pptxE governance.pptx
E governance.pptx
 
Human Resource Information System
Human Resource Information SystemHuman Resource Information System
Human Resource Information System
 
Introduction to TQM
Introduction to TQMIntroduction to TQM
Introduction to TQM
 
Fuzzy Logic
Fuzzy LogicFuzzy Logic
Fuzzy Logic
 
Human Resource Management: Training and Development (HRM)
Human Resource Management: Training and Development (HRM)Human Resource Management: Training and Development (HRM)
Human Resource Management: Training and Development (HRM)
 
Work Breakdown Structure (WBS)
Work Breakdown Structure (WBS)Work Breakdown Structure (WBS)
Work Breakdown Structure (WBS)
 
Materials Codification and Classification
Materials Codification and ClassificationMaterials Codification and Classification
Materials Codification and Classification
 
Economic Ordered Quantity (EOQ)
Economic Ordered Quantity (EOQ)Economic Ordered Quantity (EOQ)
Economic Ordered Quantity (EOQ)
 
Materials Management in Civil Engineering
Materials Management in Civil EngineeringMaterials Management in Civil Engineering
Materials Management in Civil Engineering
 
Ready Mix Concrete (RMC) Production Efficiency
Ready Mix Concrete (RMC) Production EfficiencyReady Mix Concrete (RMC) Production Efficiency
Ready Mix Concrete (RMC) Production Efficiency
 
Ready Mix Concrete (RMC) quality controls
Ready Mix Concrete (RMC) quality controls Ready Mix Concrete (RMC) quality controls
Ready Mix Concrete (RMC) quality controls
 
Grouting Methods
Grouting Methods Grouting Methods
Grouting Methods
 

Recently uploaded

result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 

Recently uploaded (20)

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 

VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY

  • 1. UNIT 2 VARIABLES AND DATA TYPES IN PYTHON Prof. Rushikesh V. Kolhe Phd Pursuing, M.Tech Civil CM Assistant Professor Department of Civil Engineering Sanjivani College of Engineering, Kopargaon
  • 2. CONTENT • What are variables ? • String data type • Numerical data type • Examples
  • 3. VARIABLES IN MATHS • A symbol used to represent a numerical value which can change • 2x = y + 1 ( Algebra ) • x = 1, y = 1 • x = 2, y = 3 • Ten years from now, Rohit will be three times older than he is today. What is his current age?
  • 4. WHAT ARE VARIABLES • Variables are used to store data • These data are stored in main memory when you run the program • Programming = data + logic • Different data types in python • Numbers • Strings • Lists • Tuple • Dictionary
  • 5. A SIMPLE EXAMPLE • What is print() here ? • What does it do ?
  • 6. WHAT ARE FUNCTIONS IN MATHS ? • Takes inputs and gives an output depending on the input • f(x) = x^2 • f(1) = 1 • f(2) = 4 • Programming functions also do the same. • Takes input and returns output ( not always ) • Many built-in functions are present in python • print() is one example – prints the input on screen • More about functions in a separate video
  • 7. WHY SHOULD I USE VARIABLES ?
  • 8. • Using variables makes programs simpler • Reduces repeated work
  • 9. Naming Variables • Can you give any name to the variables ? • What are errors ?
  • 10. WHAT ARE ERRORS IN PYTHON ? • My name is Shivam vs Is name Shivam my ? • My nam is Shivam vs My name is Shivam ? • My name are Shivam vs My name is Shivam ? • Every language has a syntax or a set of rules to follow while writing it • Python also has a syntax • If you do not follow it, you will get errors. • More about ”errors in python” in a separate video
  • 12. RULE 1 - Variable names can contain only letters, numbers, and underscores. They can start with a letter or an underscore, but not with a number.
  • 13. SUPPOSE YOU WANT TO WRITE TWO DIFFERENT MESSAGES ?
  • 14.
  • 15. RULE 2 - Spaces are not allowed in variable names, but underscores can be used to separate words in variable names.
  • 16. RULE 3 - Avoid using Python keywords and function names as variable names; that is, do not use words that Python has reserved for a particular programmatic purpose, such as the word print.
  • 17. WHAT ARE KEYWORDS IN PYTHON? • These are reserved words in python which are used to define the syntax of python language. • In English, “is”, “the”, “you” etc. are reserved words which defines the grammar. • Keywords have different meaning for Python language. • Do not use them in your variables or function names.
  • 18. LIST OF KEYWORDS IN PYTHON
  • 19.
  • 21. SOME OTHER IMPORTANT POINTS TO NOTE • Variable names should be short but descriptive. • name is better than writing n • message is better than writing m or my_name_message • Be careful when using the lowercase letter l and the uppercase letter O because they could be confused with the numbers 1 and 0.
  • 22. It can take some practice to learn how to create good variable names, especially as your programs become more interesting and complicated. As you write more programs and start to read through other people’s code, you’ll get better at coming up with meaningful names.
  • 23. AVOIDING NAME ERRORS WHEN USING VARIABLES
  • 24. FINDING THE DATA TYPE OF A VARIABLE • Use type() built-in function
  • 26. WHAT ARE STRINGS ? • A string is a series of characters • Characters – alphabets, digits, special characters, white spaces • Anything inside quotes is considered a string in Python • You can use single or double quotes around your strings
  • 27.
  • 28.
  • 29. SINGLE QUOTE VS DOUBLE QUOTE ? • You can use any of these • Be consistent • Exceptions – print these text on screen: • The language 'Python' is named after Monty Python, not the snake. • I told my friend, "Python is my favorite language!"
  • 30. ASSIGNMENT: Try to find out if it is possible to print first message by using single quotes and second by using double quotes and how ?
  • 33. • print() vs message.lower() • These built-in functions are specific to strings. • print() is specific to multiple data types • The dot(.) operator acts on the variable and converts it into upper/lower cases • The original data doesn’t change
  • 34. TITLE FUNCTION • Converts the first character of each word into upper case
  • 35. LEN FUNCTION • Outputs the length of the string • A single character is of length 1 • Characters can be alphabets or digits or punctuation or white spaces
  • 36. STRIP FUNCTIONS – strip(), lstrip(), rstrip() • Remove the extra whitespaces from a string
  • 37. rstrip() – remove whitespace at right end
  • 38. lstrip() – remove whitespace from left end
  • 39. strip() – remove spaces from both ends
  • 41. COMBINE THESE TWO TO PRODUCE FULL NAME
  • 42. Use f-strings • Feature is available from python 3.6 • Start string with f – f stands for format • Put braces around variable name
  • 43.
  • 44.
  • 46. Adding Whitespace to Strings with Tabs or Newlines • In programming, whitespace refers to any nonprinting character, such as spaces, tabs, and end-of-line symbols. • You can use whitespace to organize your output so it’s easier for users to read.
  • 47. Add a tab to your text
  • 48. Add newline to your text
  • 50. What are numbers ? • Integers = 1, 2, 3 • Floats = 1.2, 2.55 • These data are used very frequently in a program.
  • 51. INTEGERS • You can add, subtract, multiply and divide python integers
  • 52.
  • 53. • Python uses two multiplication symbols to represent exponents.
  • 54. MULTIPLE OPERATORS IN ONE EXPRESSION
  • 55. • The spacing in these examples has no effect on how Python evaluates the expressions • Clarity • More about precedence of operators in a future video
  • 56. FLOATS • Python calls any number with a decimal point a float. • This term is used in most programming languages, and it refers to the fact that a decimal point can appear at any position in a number. • Example: 1.2, 12.35
  • 57.
  • 58. This happens in all languages and is of little concern. Python tries to find a way to represent the result as precisely as possible, which is sometimes difficult given how computers have to represent numbers internally.
  • 62. MULTIPLE ASSIGNMENTS • You can assign values to more than one variable using just a single line. • This can help shorten your programs and make them easier to read. • You’ll use this technique most often when initializing a set of numbers.
  • 63. CONSTANTS IN PYTHON • A constant is like a variable whose value stays the same throughout the life of a program. • Python doesn’t have built-in constant types, but Python programmers use all capital letters to indicate a variable should be treated as a constant and never be changed.