SlideShare a Scribd company logo
1 of 3
Download to read offline
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
UNIT II
DATA TYPES AND VARIABLES IN PYTHON
Introduction data types and variables, types of Data types and variables
Python is a dynamically typed language, which means you don't have to declare the type of a
variable when you create one. This flexibility allows Python to be very user-friendly and easy
to work with. Below, we delve into the details of data types and variables in Python.
2.1 Introduction to Data Types and Variables
Variables in Python are more than just names bound to objects. They serve as references to
objects stored in memory. Unlike some other programming languages, Python does not require
explicit declaration to reserve memory space. The declaration happens automatically when you
assign a value to a variable. The equal sign (=) is used to assign values to variables.
Dynamic Typing
Python is dynamically typed, which means the type of variable is determined at runtime, not in
advance. This provides flexibility but requires understanding how types can change.
Variable Naming Conventions
• Names can start with a letter or an underscore, not with a number.
• Names can contain letters, numbers, and underscores.
• Python is case-sensitive; thus, Variable is different from variable.
Variables are essentially the names you give to computer memory locations which are used to
store values in a programming language. In Python, variables are created the moment you
assign a value to them.
Data Types are an important concept in programming. They are the classification or
categorization of data items. They represent the kind of value that tells what operations can be
performed on a particular data. Since everything is an object in Python programming, data
types are actually classes and variables are instance (object) of these classes.
2.2 Types of Data Types in Python
Python has various standard data types that are used to define the operations possible on them
and the storage method for each of them. Python data types can be broadly classified into:
1. Numeric Types: Integers, Floating point numbers, and Complex numbers.
1. Integers (int): Represent whole numbers, positive or negative, without decimals,
of unlimited length. Commonly used in counting, indexing, and operations that
require precision without fractional parts.
• Integers (int): Whole numbers, positive or negative, without decimals of
unlimited length.
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
2. Floating Point Numbers (float):
Represent real numbers and contain one or more decimals. Suitable for
measurements, scientific calculations, and any operation that requires fractional
numbers.
Precision might be an issue for very high precision requirements due to the way
floating-point numbers are stored.
• Floating Point Numbers (float): Numbers, positive or negative, containing one
or more decimals.
3. Complex Numbers (complex):
Written with a "j" as the imaginary part (x + yj), where x and y are floats.
Used in fields requiring complex number calculations such as signal processing,
engineering, and specific branches of mathematics.
• Complex Numbers (complex): Written with a "j" as the imaginary part: x + yj.
2. Sequence Types: Lists, Tuples, and Strings.
1. Lists (list):
Ordered and changeable (mutable) collections, allowing duplicate members.
Versatile for storing a sequence of objects that may need to be altered during the
program lifecycle, such as adding, removing, or changing elements.
2. Tuples (tuple):
Ordered collections like lists, but unchangeable (immutable).
Suitable for fixed data sets. They can be used as keys in dictionaries or as
elements of sets, where immutability is necessary.
3. Strings (str):
Ordered sequences of characters, making them immutable.
Used for text representation, including processing and manipulation of textual
data like names, messages, and outputs.
3. Mapping Type: Dictionary.
• Dictionary (dict): Unordered, changeable, and indexed collections, written
with curly brackets. Dictionaries have keys and values.
4. Set Types: Sets and Frozen Sets.
• Set (set): Unordered and unindexed collections, written with curly brackets.
However, unlike dictionaries, they are unordered collections of unique
elements.
• Frozen Set (frozenset): Immutable and hashable version of a set.
5. Boolean Type (bool): Represents True or False values and is used to perform logical
operations.
6. Binary Types: Binary, Bytearray, Memoryview.
• Bytes (bytes): Immutable sequence of bytes.
• Bytearray (bytearray): Mutable sequence of bytes.
• Memoryview (memoryview): Memory view object of the byte data.
Variables in Python
Variables in Python are created by a simple assignment operation, with the variable name on
the left, the assignment operator =, and the value on the right. Python infers the type of the
variable based on the value assigned to it.
• Dynamic Typing: Python allows you to reassign variables to different data types.
• Naming Conventions: Variable names can be short (a, x, y) or descriptive (age,
car_speed, total_volume). However, they must start with a letter or an underscore,
cannot begin with a number, and are case-sensitive.
Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon.
2.3 Mutable vs Immutable Data Types
• Mutable: Their content can be changed without changing their identity. Examples
include lists, dictionaries, and sets.
• Immutable: Their content cannot be changed once they are created. Examples include
integers, floats, strings, and tuples.
Summary
Understanding data types and variables is fundamental in Python as it affects how data can be
manipulated and stored. Each data type in Python is designed with a specific purpose in mind,
offering a wide range of functionalities to perform various operations on data efficiently.
Variables in Python are easy to declare and use, promoting a cleaner and more readable
codebase.

More Related Content

Similar to Programming in Civil Engineering_UNIT 2_NOTES

What is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfWhat is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfNitish Banga
 
What is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfWhat is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfNitish Banga
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4FabMinds
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdfalaparthi
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of funcSanjayKumarMahto1
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.pptjaba kumar
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
Iot with raspberry pi insustrial training
Iot with raspberry pi insustrial trainingIot with raspberry pi insustrial training
Iot with raspberry pi insustrial trainingPREM NARAYAN MAITHIL
 
basics-of-python-programming3.pptx
basics-of-python-programming3.pptxbasics-of-python-programming3.pptx
basics-of-python-programming3.pptxRohanSharma351159
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning ParrotAI
 

Similar to Programming in Civil Engineering_UNIT 2_NOTES (20)

Data Science Using Python.pptx
Data Science Using Python.pptxData Science Using Python.pptx
Data Science Using Python.pptx
 
GE3151_PSPP_UNIT_2_Notes
GE3151_PSPP_UNIT_2_NotesGE3151_PSPP_UNIT_2_Notes
GE3151_PSPP_UNIT_2_Notes
 
What is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfWhat is the Basic use of python (7).pdf
What is the Basic use of python (7).pdf
 
What is the Basic use of python (7).pdf
What is the Basic use of python (7).pdfWhat is the Basic use of python (7).pdf
What is the Basic use of python (7).pdf
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
 
Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4Python Programming | JNTUK | UNIT 1 | Lecture 4
Python Programming | JNTUK | UNIT 1 | Lecture 4
 
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Data Handling
Data HandlingData Handling
Data Handling
 
Chapter - 2.pptx
Chapter - 2.pptxChapter - 2.pptx
Chapter - 2.pptx
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func1 cs xii_python_functions_introduction _types of func
1 cs xii_python_functions_introduction _types of func
 
Python - Module 1.ppt
Python - Module 1.pptPython - Module 1.ppt
Python - Module 1.ppt
 
Phython presentation
Phython presentationPhython presentation
Phython presentation
 
1. python programming
1. python programming1. python programming
1. python programming
 
Iot with raspberry pi insustrial training
Iot with raspberry pi insustrial trainingIot with raspberry pi insustrial training
Iot with raspberry pi insustrial training
 
basics-of-python-programming3.pptx
basics-of-python-programming3.pptxbasics-of-python-programming3.pptx
basics-of-python-programming3.pptx
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
 

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 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESProgramming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESRushikesh Kolhe
 
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYVARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYRushikesh 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 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTESProgramming in Civil Engineering_UNIT 1_NOTES
Programming in Civil Engineering_UNIT 1_NOTES
 
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDYVARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
VARIABLES AND DATA TYPES IN PYTHON NEED TO STUDY
 
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

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
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
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGSIVASHANKAR N
 
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
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
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
 
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
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
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
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
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
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
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
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 

Recently uploaded (20)

VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
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
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTINGMANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
MANUFACTURING PROCESS-II UNIT-1 THEORY OF METAL CUTTING
 
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
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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
 
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...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
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
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
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...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
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)
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
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
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 

Programming in Civil Engineering_UNIT 2_NOTES

  • 1. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. UNIT II DATA TYPES AND VARIABLES IN PYTHON Introduction data types and variables, types of Data types and variables Python is a dynamically typed language, which means you don't have to declare the type of a variable when you create one. This flexibility allows Python to be very user-friendly and easy to work with. Below, we delve into the details of data types and variables in Python. 2.1 Introduction to Data Types and Variables Variables in Python are more than just names bound to objects. They serve as references to objects stored in memory. Unlike some other programming languages, Python does not require explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. Dynamic Typing Python is dynamically typed, which means the type of variable is determined at runtime, not in advance. This provides flexibility but requires understanding how types can change. Variable Naming Conventions • Names can start with a letter or an underscore, not with a number. • Names can contain letters, numbers, and underscores. • Python is case-sensitive; thus, Variable is different from variable. Variables are essentially the names you give to computer memory locations which are used to store values in a programming language. In Python, variables are created the moment you assign a value to them. Data Types are an important concept in programming. They are the classification or categorization of data items. They represent the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. 2.2 Types of Data Types in Python Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. Python data types can be broadly classified into: 1. Numeric Types: Integers, Floating point numbers, and Complex numbers. 1. Integers (int): Represent whole numbers, positive or negative, without decimals, of unlimited length. Commonly used in counting, indexing, and operations that require precision without fractional parts. • Integers (int): Whole numbers, positive or negative, without decimals of unlimited length.
  • 2. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. 2. Floating Point Numbers (float): Represent real numbers and contain one or more decimals. Suitable for measurements, scientific calculations, and any operation that requires fractional numbers. Precision might be an issue for very high precision requirements due to the way floating-point numbers are stored. • Floating Point Numbers (float): Numbers, positive or negative, containing one or more decimals. 3. Complex Numbers (complex): Written with a "j" as the imaginary part (x + yj), where x and y are floats. Used in fields requiring complex number calculations such as signal processing, engineering, and specific branches of mathematics. • Complex Numbers (complex): Written with a "j" as the imaginary part: x + yj. 2. Sequence Types: Lists, Tuples, and Strings. 1. Lists (list): Ordered and changeable (mutable) collections, allowing duplicate members. Versatile for storing a sequence of objects that may need to be altered during the program lifecycle, such as adding, removing, or changing elements. 2. Tuples (tuple): Ordered collections like lists, but unchangeable (immutable). Suitable for fixed data sets. They can be used as keys in dictionaries or as elements of sets, where immutability is necessary. 3. Strings (str): Ordered sequences of characters, making them immutable. Used for text representation, including processing and manipulation of textual data like names, messages, and outputs. 3. Mapping Type: Dictionary. • Dictionary (dict): Unordered, changeable, and indexed collections, written with curly brackets. Dictionaries have keys and values. 4. Set Types: Sets and Frozen Sets. • Set (set): Unordered and unindexed collections, written with curly brackets. However, unlike dictionaries, they are unordered collections of unique elements. • Frozen Set (frozenset): Immutable and hashable version of a set. 5. Boolean Type (bool): Represents True or False values and is used to perform logical operations. 6. Binary Types: Binary, Bytearray, Memoryview. • Bytes (bytes): Immutable sequence of bytes. • Bytearray (bytearray): Mutable sequence of bytes. • Memoryview (memoryview): Memory view object of the byte data. Variables in Python Variables in Python are created by a simple assignment operation, with the variable name on the left, the assignment operator =, and the value on the right. Python infers the type of the variable based on the value assigned to it. • Dynamic Typing: Python allows you to reassign variables to different data types. • Naming Conventions: Variable names can be short (a, x, y) or descriptive (age, car_speed, total_volume). However, they must start with a letter or an underscore, cannot begin with a number, and are case-sensitive.
  • 3. Prepared by Prof. Rushikesh Kolhe, Asst. Professor, Department of Civil Engineering, SCOE, Kopargaon. 2.3 Mutable vs Immutable Data Types • Mutable: Their content can be changed without changing their identity. Examples include lists, dictionaries, and sets. • Immutable: Their content cannot be changed once they are created. Examples include integers, floats, strings, and tuples. Summary Understanding data types and variables is fundamental in Python as it affects how data can be manipulated and stored. Each data type in Python is designed with a specific purpose in mind, offering a wide range of functionalities to perform various operations on data efficiently. Variables in Python are easy to declare and use, promoting a cleaner and more readable codebase.